Array-promo

Question

Print reverse of a number.

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					import java.util.Scanner;
 public class reverseOfNUmber
{
  public static void main()
  {
    int num =0,reversedInteger = 0, remainder, temp=0;
    Scanner sc = new Scanner(System.in);
    System.out.println("ENTER A NUMBER");
    num = sc.nextInt(); 
    temp= num;
    /* reversed integer is stored in variable */
    while( temp != 0 )
    {
        remainder = temp % 10;
        reversedInteger = reversedInteger * 10 + remainder;
        temp /= 10;
    }
    
    System.out.println(reversedInteger);
  }
}

				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *