Back
You can use the below code to reverse a number using an array:
public static void reverse(int[] array) { if (array == null) { return; } int i = 0; int j = array.length - 1; int temp; while (j > i) { temp = array[j]; array[j] = array[i]; array[i] = temp; j--; i++; }}
public static void reverse(int[] array) {
if (array == null) {
return;
}
int i = 0;
int j = array.length - 1;
int temp;
while (j > i) {
temp = array[j];
array[j] = array[i];
array[i] = temp;
j--;
i++;
I hope this will help.
Want to know more about Java? Prefer this tutorial on Learn Java.
Want to become a Java Expert? join Java Certification now!!
31k questions
32.8k answers
501 comments
693 users