Q:

Write a Java Program to find Reverse Number using While Loop

belongs to collection: Java Basic Solved Programs

0

Reverse number means reverse the position of all digits of any number.

For example : Reverse of 435 is 534.

For this program you need modulus operator concept and while loop, while loop is used for check condition and modulus used for find the remainder.

All Answers

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

SOURCE CODE ::

import java.util.Scanner;

public class ReverseNumber {

public static void main(String[] args) {
 
 int n,i,reverse=0,k;
 
 Scanner sc = new Scanner(System.in);
 System.out.print("Enter the no. which u want to reverse : ");
 n=sc.nextInt();
 k=n;
 while(n>0)
 {
 i=n%10;
 reverse=reverse*10+i;
 n=n/10;
 }
 System.out.println("Reverse of " + k + " is : "+ reverse);
 
 }
 
}

OUTPUT ::

Enter the no. which u want to reverse : 123456

Reverse of 123456 is : 654321

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

total answers (1)

Java Basic Solved Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a Java Program to display Fibonacci Series u... >>
<< Write a Java Program to find Factorial using While...