Write a program to check palindrome or not
package Programs;
public class Palindrome {
public static void main(String[] args) {
int number=122;
int temp=number;
int rev=0,rem;
while (temp!=0){
rem=temp%10;
rev=rev*10+rem;
temp=temp/10;
}
if (number==rev){
System.out.println(number+ " is palindrome");
}
else {
System.out.println(number+ " not palindrome");
}
}
}
Output :
Write a program using user input (Scanner class)
public class Palindrome
{
public static void main(String[] args)
{
int number;
System.out.println("enter the number");
Scanner scanner=new Scanner(System.in);
number=scanner.nextInt();
int temp=number;
int rev=0,rem;
while (temp!=0)
{
rem=temp%10;
rev=rev*10+rem;
temp=temp/10;
}
if (number==rev){
System.out.println(number+ " is palindrome");
}
else {
System.out.println(number+ " not palindrome");
}
}
}
Output :
package Programs;
public class Palindrome {
public static void main(String[] args) {
int number=122;
int temp=number;
int rev=0,rem;
while (temp!=0){
rem=temp%10;
rev=rev*10+rem;
temp=temp/10;
}
if (number==rev){
System.out.println(number+ " is palindrome");
}
else {
System.out.println(number+ " not palindrome");
}
}
}
Output :
Write a program using user input (Scanner class)
public class Palindrome
{
public static void main(String[] args)
{
int number;
System.out.println("enter the number");
Scanner scanner=new Scanner(System.in);
number=scanner.nextInt();
int temp=number;
int rev=0,rem;
while (temp!=0)
{
rem=temp%10;
rev=rev*10+rem;
temp=temp/10;
}
if (number==rev){
System.out.println(number+ " is palindrome");
}
else {
System.out.println(number+ " not palindrome");
}
}
}
Output :
Click to next or Start with your Choice
-Important Programs for Freshers
- Palindrome Number
- Prime Number
- Swapping Number
- Leap Year
- Odd and Even Number
- Fibonacci Series
- Armstrong Number
- Factorial Number
- Print Table
Sorting and Searching
Programs
Learn Pattern Programs
- Alphabet
pattern program in java
- Star Pattern Programs in Java
- Square
pattern programs in java
- Diamond
Star pattern programs in java
- Number
Pattern Programs in java
- Diagonal
pattern program in java
Click to learn Array
Programs
- 4
ways to print Array in Java
- 2-D
Array in Java
- Anonymous
Array in Java
- Single
Dimensional Array in Java
- Find
Second Largest Number in Array
- Delete
an Element in Array in Java
- Common
Element in Array in Java
- Missing
Element in Array
- Insert
Element in Array
- Reverse Array in Java
- Merge Two Array in Java
- Smallest
and Largest Elements in Array
- Find
Odd and Even Number in Array
Click
to Learn MySQL
No comments:
Post a Comment