In an exercice at class, we need to ask to the user (in these example) ten numbers and then the program just reverse it. Already check it and the way to do it it's with a for statement.
for (int i = 0 ; i < n ; i ++) {
System.out.println("In the position "+i+" now we have these one "+nkb[in-1-i]);
}
Ok these is a solution and it's ok, but my question is, can be possible in other way than with another for
statement?
Here it's the full code of the exercice.
package *;
import java.util.Scanner;
public class * {
// n = limit of inputs
private static final int n = 10;
static Scanner kb = new Scanner(System.in);
public static void main(String[] args) {
//nkb = number from keyboard
int [] nkb = new int[n];
// in = number of length
int in = nkb.length;
//for input user
for (int i = 0; i < n; i ++){
System.out.println("Writte a number: ");
nkb[i] = kb.nextInt();
}//end for
for (int i = 0; i < n; i ++){
System.out.println("In these position "+i+" now we have these number: "+nkb[in-1-i]);
}//end for reverse
}//end method
}//end class