Hello,
This was my solution:
import java.util.*;
import java.lang.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
ArrayList<Integer> a = new ArrayList<Integer>();int t;
while(sc.hasNextLine() && (t = Integer.parseInt(sc.nextLine())) != 42)
a.add(t);
int[] b = sorted(a);
for(int i : b) System.out.println(i);
}
static int[] sorted(ArrayList<Integer> a){
Object[] g = a.toArray(); int len = g.length;
int[] x = new int[len];
for(int i = 0; i < len; i++)
x[i] = (int) g[i];
for(int i = 0; i < len; i++){
for(int j = 0; j < len - i - 1; j++){
if(x[j] > x[j + 1]){
int t = x[j];
x[j] = x[j + 1];
x[j + 1] = t;
}
}
}
return x;
}
}
I implemented the sorting part since the problem said:
Your program is to use the brute-force approach in order to find the Answer to Life, the Universe, and Everything. More precisely... rewrite small numbers from input to output. Stop processing input after reading in the number 42. All numbers at input are integers of one or two digits.
However, my solution was only accepted after I removed the sorting part.
Why was my interpretation of the problem statement wrong?