Q:

Java Program to reverse a number using for Loop

0

Java Program to reverse a number using for Loop by getting input from the user

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
class demo1
{
   public static void main(String args[])
   {
      int num=0;
      int reverse =0;
      System.out.println("Input your number");
      Scanner n = new Scanner(System.in);
      num = n.nextInt();
 
      for( ;num != 0; )
      {
          reverse = reverse * 10;
          reverse= reverse + num%10;
          num = num/10;
      }

      System.out.println("Reverse of a number is: "+reverse);
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now