Reverse Number Program in Java

Google Advertisements

Prev Tutorial Next Tutorial

Java Program to Reverse Number

Reverse number means reverse the position of all digits of any number. For example reverse of 839 is 938. 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.

reverse number program in java

In this session we discuss about reverse any number suppose user enter 324 and we need to write code for this which give 423 as a output.

Reverse Number Program in Java

import java.util.Scanner;
class Reverse 
{
public static void main(String[] args) 
{
int no,rev=0,r,a;
Scanner s=new Scanner(System.in);
System.out.println("Enter any no.: ");
no=s.nextInt();
a=no;
while(no>0)
{
r=no%10;
rev=rev*10+r;
no=no/10;
}
System.out.println("Reverse: "+rev);
}
}

Output

Enter any no. :
153
Reverse: 351

Syntax to compile and run java program

Syntax

for compile -> c:/>javac Reverse.java
for run -> c:/>java Reverse

Explanation of Code

  • Scanner s=new Scanner(System.in): are used for receive input from keyboard.
  • nextInt(): method are used for get integer type value from keyboard.
  • System.out.println("....."): are used for display message on screen or console.

Prev Tutorial Next Tutorial

Google Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: [email protected] or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Media.net Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: [email protected] or 9999595223 Try this Keyword C++ Programs