Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- GTU Practical EXERCISES
- 29th March,2023
- Karishma and Nency
- Write a program in Java to reverse the digits of a
- number using while loop
- */
- import java.util.Scanner;
- class q3
- {
- public static void main(String args[])
- {
- int n,s,rev=0;
- Scanner sc=new Scanner(System.in);
- System.out.println("Enter number=>");
- n=sc.nextInt();
- while(n!=0)
- {
- s=n%10;
- rev=rev*10+s;
- n=n/10;
- }
- System.out.println("Reverse is "+rev);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement