Programs for reversing a number
Case 1:
import java.util.*;
class Demo
public static void main(String[] args)
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int num = sc.nextInt();
int rev = 0;
while(num!=0)
rev = rev*10+num%10;
num=num/10;
System.out.println("reverse of number is "+rev);
Case 2:
import java.util.*;
class Demo
public static void main(String[] args)
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int num = sc.nextInt();
StringBuffer sb = new StringBuffer(String.valueOf(num));
System.out.println("reversed number is "+sb.reverse());
Case 3:
import java.util.*;
class Demo
public static void main(String[] args)
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number");
int num = sc.nextInt();
StringBuilder sb = new StringBuilder();
sb.append(num);
System.out.println("reversed number is "+sb.reverse());