This java Code will reverse the given Integer number. (Integer number will be Ignoring any 0 value at beginning of Given Integer or Reversed integer value)
import java.util.Scanner;
public class Test {
public static int reverseNumber (int value) {
int tempValue = 0;
while (value > 9) {
tempValue = tempValue*10;
tempValue += value%10;
value = value/10;
if (value <= 9) {
tempValue = tempValue*10;
tempValue += value%10;
}
}
value = tempValue;
return value;
}
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Enter number to reverse : ");
int value = input.nextInt();
System.out.println("Reversed Numver: " + reverseNumber(value));
}
}
import java.util.Scanner;
public class Test {
public static int reverseNumber (int value) {
int tempValue = 0;
while (value > 9) {
tempValue = tempValue*10;
tempValue += value%10;
value = value/10;
if (value <= 9) {
tempValue = tempValue*10;
tempValue += value%10;
}
}
value = tempValue;
return value;
}
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("Enter number to reverse : ");
int value = input.nextInt();
System.out.println("Reversed Numver: " + reverseNumber(value));
}
}
No comments:
Post a Comment