In this tutorial I would like to share with you a simple program that I wrote in Java that will ask the user to enter a number in integer format then it will reverse the arrangement of numbers. The code is very straight forward to follow and understand it will serve as a basis for anyone that are new in Java programming.
If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.
People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360.
Sample Output of Our Program
Program Listing
import java.lang.*;
import java.util.Scanner;
class rev
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
char a;
do
{
int num1=0,r=0;
int solve_value=0;
System.out.println("==============================================");
System.out.println("|| <<< REVERSE A NUMBER PROGRAM >>> ||");
System.out.println("==============================================");
System.out.print("\n");
System.out.print("Enter a Number :=>");
num1 = in.nextInt();
System.out.println("\n");
System.out.println("=======================");
System.out.println("|| DISPLAY RESULT ||");
System.out.println("=======================");
System.out.println("\n");
System.out.println("Original Number Arrangement :=> " +num1 +".");
while(num1>0)
{
r=num1%10;
solve_value=(solve_value*10)+r;
num1=num1/10;
}
System.out.println("Reverse of number result :=> " +solve_value +".");
System.out.println("\n");
System.out.print(" Do you Want To Continue(Y/N) :=> ");
a=in.next().charAt(0);
} while(a=='Y'|| a=='y');
System.out.println("\n");
System.out.println("\t ===== END OF PROGRAM ======");
System.out.println("\n");
}
}
No comments:
Post a Comment