Reverse number Program is program which reverse the number given by user and if both the numbers are same reverse and given reverse .For example user enters 123 the reverse number is 321.and if user enters number 121 and if its reverse number is same 121, then the number is called palidrona.This program have static reverse() method which invoke and return reverse intiger.
Program
import java.util.Scanner; // this package util and Class Scanner is declared to take input from user
/*
*@ scanner class
* @author khant vyas*/
public class reverse // name of class
{
public static boolean Ispalidrona(int rev)// its method of boolean type
{
if (rev==reverse.reverse(rev))
{
System.out.println("number is palidrona ");
return true;
}
else
System.out.println("number is not palidrona");
return false;
}
public static int reverse(int rev) /* method reverse of integer type with intiger argument and return integer value*/
{
int result=0;
while(rev>0)
{
int num=rev%10;
rev=rev/10;
result= result*10+num;
}
return result;
}
public static void main(String[] args)
{
int a;// variable a takes user input in program
Scanner sc = new Scanner(System.in); // sc is object to the Scanner class
System.out.println("Enter the number you wanted to reverse ");
a=sc.nextInt();// nextInt() method is used accept intiger value from user
reverse(a); // passing a variable in reverse() method
Ispalidrona(reverse(a));// this method takes return value from reverse function
System.out.println(" reverse string is"+reverse(a));
}
}