Advertisement
netx_iit

Reverse number

Mar 28th, 2023 (edited)
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | Source Code | 0 0
  1. /*
  2.     GTU Practical EXERCISES
  3.     29th March,2023
  4.     Karishma and Nency
  5.     Write a program in Java to reverse the digits of a
  6.     number using while loop
  7. */
  8. import java.util.Scanner;
  9. class q3
  10. {
  11.     public static void main(String args[])
  12.     {
  13.         int n,s,rev=0;
  14.         Scanner sc=new Scanner(System.in);
  15.         System.out.println("Enter number=>");
  16.         n=sc.nextInt();
  17.         while(n!=0)
  18.         {
  19.             s=n%10;
  20.             rev=rev*10+s;
  21.             n=n/10;
  22.         }
  23.         System.out.println("Reverse is "+rev);
  24.     }
  25. }
Tags: BASIC LOOP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement