Tutorials for Java ,Core java ,Advance java ,oracle ,HTML, CSS, JavaScript, Java and other programming language tutorial Learn Java tutorial for beginners with examples in eclipse online. Java tutorial point for core java, servlet, jsp, struts, spring, for learning web technologies online. Content includes tutorials and references relating to HTML, CSS, JavaScript, PHP, AngularJS, SQL, Bootstrap, Node.js, and jQuery this is a website like w3school tutorialspoint etc

Search This Blog


Header Ads

Friday, 1 June 2018

Reverse a number using while Loop


Reverse a number using while Loop

import java.util.Scanner;
class ReverseNumberWhile
   public static void main(String args[])
      int num=0;
      int reversenum =0;
      System.out.println("Input your number and press enter: ");
      //This statement will capture the user input
      Scanner in = new Scanner(System.in);
      //Captured input would be stored in number num
      num = in.nextInt();
      //While Loop: Logic to find out the reverse number
      while( num != 0 )
          reversenum = reversenum * 10;
          reversenum = reversenum + num%10;
          num = num/10;

      System.out.println("Reverse of input number is: "+reversenum);

No comments:

Post a Comment