I cannot pass the test.

    /* Array of strings in reverse order
1. Create an array of 10 strings.
    2. Read from the keyboard 8 strings and store them in the array.
    3. Display to the screen the contents of the entire array (10 items) in reverse order. Each item should be on a new line.
*/

public class Solution
{
    public static void main(String[] args) throws Exception
    {
        //add your code here
        String [] array = new String [8];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        for(int i=0; i<array.length; i++)
            array[i] = br.readLine();

        for(int i=0; i<10; i++)
        {
            for(int j=1; j<=array.length; j++)
                System.out.println(array[array.length - j]);

        }

    }
}

asked 30 Jul '17, 08:40

genek's gravatar image

genek
174
accept rate: 0%


Theres a simple mistake in task description.

Should be:

String [] array = new String [10];
link

answered 30 Jul '17, 08:58

YourDoom's gravatar image

YourDoom
1811
accept rate: 35%

ok and 1 for less. I've read the description wrong.

link

answered 30 Jul '17, 10:09

genek's gravatar image

genek
174
accept rate: 0%

It passed too.

public class Solution

{

public static void main(String[] args) throws Exception
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String[] array = new String[10];

    for (int i = 0; i < array.length; i++)
        array[i] = reader.readLine();

    for (int i = 1; i <= array.length; i++)
        System.out.println(array[array.length - i]);
}

}

link

answered 30 Aug, 06:41

Demotivator's gravatar image

Demotivator
11
accept rate: 0%

public static void main(String[] args) throws Exception
{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String [] list = new String[10];
    for(int i = 0; i<list.length -2 ; i++)
    {
        list[i] = reader.readLine();
    }
      for(int i = list.length-1; i>=0 ; i--)
    {
        System.out.println(list[i]);
    }

}
link

answered 06 Nov, 16:13

Anna315510's gravatar image

Anna315510
1
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×13
×9
×5

Asked: 30 Jul '17, 08:40

Seen: 903 times

Last updated: 06 Nov, 16:13