Palindrome Number In Java Using For Loop

Palindrome program in java required simple steps. In this article, I am going to share with you three types of “java program for palindrome” to find ‘palindrome number in java’. While designing the palindrome program few parts are common in every java code for palindrome. Such as Scanner class and of the methods, Which is significantly required to get the length for the input in this program to find palindrome.

simple palindrome program in java for string

The suggested question with the solution

Below I have designed all the automated java code for palindrome. Where you all just required to give the input of some number to in this all program to find palindrome. All below designed I have tried to make simple and quickest and maybe I have used some of the useless variables to make you better-understanding palindrome number in java.

Here, let’s see first palindrome number in java using for loop with function. Every programmer knows that using a loop make any program sorter and easier. On the internet, I have seen the bulk of people asking how to make a program of palindrome number.

Some of the similar questions here:-

  • Simple palindrome program in java for string
  • is palindrome possible program in java
  • palindrome program in java using reverse method
  • palindrome number in java using for loop

So above all asked important questions are same only methods are different from each other in this palindrome program. Apart from the above, many more questions are available but few I have shortlisted to make you better understand this palindrome java program. Also, I have uploaded the palindrome program in java.txt file.

Tranding java 

Palindrome program

 Palindrome number in java using for loop

import java.util.*;
public class pali2
{
static int sum;
static int pali(int x,int count)
{
int reminder;
for (int i=0; i<count; i++)
{
reminder=x%10;
sum=sum*10+reminder;
int devide=x/10;
x=devide;
}
return(sum);
}
static void comp(int x, int y)
{
if(x==y)
{
System.out.println(“This is palindrome number ::”+x);
}else
{
System.out.println(“This is not palindrome number ::”+x);
}
}
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
int num1=input.nextInt();
String numberAsString = Integer.toString(num1);
int count=numberAsString.length();
pali(num1, count);
pali2 obj=new pali2();
int initionalizevalue=obj.sum;
comp(num1, initionalizevalue);
}
}

java program for palindrome ::Second

import java.util.*;
public class rev
{
public static void main(String[] args)
{
Scanner input=new Scanner (System.in);
int x=input.nextInt();
int y=x;
int b=0;
while (x>0)
{
int a=x%10;
b=b*10+a;
x=x/10;
}
if (y==b)
{
System.out.println(“This is Palindrome number:: ” +y);
}else
{
System.out.println(“This is not Palindrome number:: ” +b);
}
}
}

java program for palindrome :Third

import java.util.*;
public class l6
{
Scanner input=new Scanner (System.in);
int a=input.nextInt();
public static void main(String [] args)
{
l6 obj=new l6();
int b=obj.a;
int c= b%10;
if (c>=1)
{
int len=String.valueOf(b).length();
System.out.println(“This is length :: ” +len);
switch (len)
{
case 1:
String con1=String.valueOf(b);
char a1=con1.charAt(0);
System.out.println(“This is not Palindrome number :: ” +b);
break;
//……………………
case 2:
String con2=String.valueOf(b);
char a2=con2.charAt(0);
char ab2=con2.charAt(1);
if (a2!=ab2)
{
System.out.println(“This is not Palindrome number :: ” +b);
} else
{
System.out.println(“This is Palindrome number :: ” +a2 +ab2);
}break;
//……………………..
case 3:
String con3=String.valueOf(b);
char a3=con3.charAt(0);
char ab3=con3.charAt(2);
if (a3!=ab3)
{
System.out.println(“This is not Palindrome number :: ” +b);
} else
{
System.out.println(“This is Palindrome number :: ” +a3 +ab3);
}
break;
//…………………………..
case 4:
String con4=String.valueOf(b);
char a4=con4.charAt(0);
char ab4=con4.charAt(1);
char abc4=con4.charAt(2);
char abcd4=con4.charAt(3);
if (a4!=abcd4 && ab4!=abc4)
{
System.out.println(“This is not Palindrome number :: ” +b);
} else
{
System.out.println(“This is Palindrome number :: ” +a4 +ab4 +abc4 +abcd4);
}
break;
//…………………………….
case 5:
String con5=String.valueOf(b);
char a5=con5.charAt(0);
char ab5=con5.charAt(1);
char abc5=con5.charAt(3);
char abcd5=con5.charAt(4);
if (a5!=abcd5 && ab5!=abc5)
{
System.out.println(“This is not Palindrome number :: ” +b);
} else
{
System.out.println(“This is Palindrome number :: ” +a5 +ab5 +abc5 +abcd5);
}
break;
//………………………………
default:
System.out.println(“This is out of range :: ” +b);
}
}
}
}

Is palindrome possible program in Java:: yes in above all the algorithm for palindrome you have passed on. Above all the program I have tried to make simple and useful to the users. And, also I have uploaded the palindrome program in java.txt file. So first see the java code for palindrome number and make understanding of palindrome logic in Java. Download uploaded files and start doing research from self.  In case if you have any problem understanding the java program for palindrome so let me know by the below-commenting box. Thanks for coming here to understanding the java code for palindrome number. If you have liked the code so let’s subscribe the website to get and every update of the Https://infosorce.com.

Speak Your Mind

*

error: Content is protected !!
DMCA.com Protection Status