Assume a sample input is: 5, 74, 16, 2, 14, 127, 53, 30, 14, 11
By reverse order, do they mean:
11, 14, 30, 53, 127, 14, 2, 16, 74, 5
or
127, 74, 53, 30, 16, 14, 14, 11, 5, 2
Current code is for the second version, but I initially tried the first version using the follow code replacing everything after line 16:
for(int i = 0; i < 10; i++)
{
nums.add(Integer.parseInt(reader.readLine()));
}
for(int i = 9; i >= 0; i--)
{
System.out.println(nums.get(i));
}
Both versions had the validator tell me not to reverse the order of the array. I don't understand what I'm being asked to do, apparently.package com.codegym.task.task07.task0719;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Display numbers in reverse order
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> nums = new ArrayList<Integer>();
int input;
for(int i = 0; i < 10; i++)
{
input = Integer.parseInt(reader.readLine());
if(nums.size() > 0)
{
int max = nums.size();
for(int n = 0; n < max; n++)
{
if(input >= nums.get(n))
{
nums.add(n,input);
break;
}
else if(n == max - 1)
{
nums.add(input);
}
}
}
else
{
nums.add(input);
}
}
for(int i = 0; i < 10; i++)
{
System.out.println(nums.get(i));
}
}
}