In this article, we will discuss the concept of the How to find reverse number of given number using method
In this post, we are going to learn how to find reverse of the given number in Java programming language
The program allows the user to enter a number and then it displays the reverse number of the given number using for loop in Java language
Program 1
import java.util.Scanner; class Reversed_Num_Method{//class declaration static int reversed_Num=0;//global variable public static void main(String args[]){ int number;//local variable Scanner scan=new Scanner(System.in); //This statements takes input from theuser System.out.print("Enter the number for find reverse: "); //get input and it is stored num variable number=scan.nextInt(); System.out.print("Reversed number of given number is: "+find_Reserve(number)); //call the method and display result } public static int find_Reserve(int number){//user-defined method for( ; number!=0;){ reversed_Num=reversed_Num*10; reversed_Num=reversed_Num+number%10; number=number/10; } return reversed_Num;//return the result to main method } }
When the above code is executed, it produces the following result
The program allows the user to enter a number and then it displays the reverse number of the given number using while loop in Java language
Program 2
import java.util.Scanner; class Reversed_Num_Methodwhile{//class declaration static int reversed_Num=0;//global variable public static void main(String args[]){ int number;//local variable Scanner scan=new Scanner(System.in); //This statements takes input from theuser System.out.print("Enter the number for find reverse: "); //get input and it is stored num variable number=scan.nextInt(); System.out.print("Reversed number of given number is: "+find_Reserve(number)); //call the method and display result } public static int find_Reserve(int number){//user-defined method int rem; while(number>0){ rem=number%10; reversed_Num=reversed_Num*10+rem; number=number/10; } return reversed_Num;//return the result to main method } }
When the above code is executed, it produces the following result
The program allows the user to enter a number and then it displays the reverse number of the given number using do-while loop in Java language
Program 3
import java.util.Scanner; class Reversed_Num_Methoddowhile{//class declaration static int reversed_Num=0;//global variable public static void main(String args[]){ int number;//local variable Scanner scan=new Scanner(System.in); //This statements takes input from theuser System.out.print("Enter the number for find reverse: "); //get input and it is stored num variable number=scan.nextInt(); System.out.print("Reversed number of given number is: "+find_Reserve(number)); //call the method and display result } public static int find_Reserve(int number){//user-defined method int rem; do{ rem=number%10; reversed_Num=reversed_Num*10+rem; number=number/10; }while(number>0); return reversed_Num;//return the result to main method } }
When the above code is executed, it produces the following result
Suggested for you
Do-while loop in Java language
Similar post
Reversed string in Java language
Reversed string in C++ language
C program to reverse a number using loops
C++ program to reverse a number using loops
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…