we have a case study to accept user input or should i say... INPUTS from user
input :: must not exceed 5 digits.
when the user inputs 0 (zero) .. it will reverse his inputs from before.
how can i reverse them??

can this could do the job?

public static void reverse(int[] b) {
   int left  = 0;          // index of leftmost element
   int right = b.length-1; // index of rightmost element
  
   while (left < right) {
      // exchange the left and right elements
      int temp = b[left]; 
      b[left]  = b[right]; 
      b[right] = temp;
     
      // move the bounds toward the center
      left++;
      right--;
   }
}//endmethod reverse

Did you write that yourself?

no, i got that over the internet...
that code is for reversing the array..

will i use twoDim array?

It may be easier to read the numbers into a simple array them read them back out using a loop that starts with the last entry and iterates downwards to the first.

wait...
what if the inputs are: 12324, 9182, 21, 2134
then the reverse: 42321, 2819, 12, 4312

Yes, you could use a simple array for each number, and put these into an array.
Java arrays are not "2D" in the sense of being a rectangular grid. They are an array of arrays, in which any array can be a different size from all the others. It's a small shift in thinking, but important.

int[][] a = new int[5][];
      a[0]= new int[2];
      a[1] = new int[99];
      // etc
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.