Program 1 : PALINDROME NUMBER
PALINDROME NUMBER IS A NUMBER WHICH ON REVERSING REMAINS IN THE SAME ORDER.
EXAMPLE: 121 , 1441 , 153351
PROGRAM :
import java.util.Scanner;
public class assign1
{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("enter a number to find out whether it is a palindrome number or not:");
int num = sc.nextInt();
int q = num;
int dig , r = 0;
while(q!=0){
dig = q%10;
r = (r*10) + dig;
q = q/10;
}
if(r==num){
System.out.println("The number entered is palindrome.");
}
else {
System.out.println("The number entered is not a palindrome");
}
}
}
PALINDROME NUMBER IS A NUMBER WHICH ON REVERSING REMAINS IN THE SAME ORDER.
EXAMPLE: 121 , 1441 , 153351
PROGRAM :
import java.util.Scanner;
public class assign1
{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.println("enter a number to find out whether it is a palindrome number or not:");
int num = sc.nextInt();
int q = num;
int dig , r = 0;
while(q!=0){
dig = q%10;
r = (r*10) + dig;
q = q/10;
}
if(r==num){
System.out.println("The number entered is palindrome.");
}
else {
System.out.println("The number entered is not a palindrome");
}
}
}
Commendable job. Request if you can add comments within program to understand very well.
ReplyDeleteTHANK YOU. I HAVE ADDED COMMENTS IN THE NEW PROGRAMS.
ReplyDelete