# A palindrome is a number or a text phrase that reads the same bac

Content type
User Generated
Rating
Showing Page:
1/4
A palindrome is a number or a text phrase that reads the
same backwards as forwards. For example each of the
following 5-digit integers is a palindrome: 12322, 44444,
54345, 45554, and 11511. Write a Java program that reads
in n (input from the user) five-digit integers and: Outputs
the numbers into separated individual digits. Determines
whether or not each number is a palindrome. Palindrome
finder program. How many times testing for palindrome? 3
Enter a 5-digit number; 12345 The digits are: 1 2 3 4 5
This number is not palindrome. Enter a 5-digit number;
12321 The digits are: 1 2 3 2 1 This number is not
palindrome. Enter a 5-digit number; 11111 The digits are:
1 1 1 1 1 This number is not palindrome.
Solution
Palindrome.java
import java.util.Scanner;//package for keyboard inputting
class Palindrome{ //main class
public static void main(String args[]){//main method
int r,sum=0,temp; //variables
Scanner sc=new Scanner(System.in);
System.out.println(\"How many times you want to
test\");

Showing Page:
2/4
int nooftests=sc.nextInt();//keyboard inputting
for(int k=0;k<nooftests;k++){
temp=0;
r=0;
sum=0;
System.out.println(\"Enter the 5digit number\");
int n=sc.nextInt();//It is the number variable to be
checked for palindrome
temp=n;
while(n>0){
r=n%10; //getting remainder
sum=(sum*10)+r;
n=n/10;
}
//code for separating digits
String strInput = String.valueOf(sum);
int len = strInput.length();
for(int i=len-1; i >=0; i--) {
System.out.print(strInput.charAt(i));
System.out.print(\" \");
}
if(temp==sum)
System.out.println(\"palindrome number \");

Showing Page:
3/4

End of Preview - Want to read all 4 pages?
Access Now
Unformatted Attachment Preview
A palindrome is a number or a text phrase that reads the same backwards as forwards. For example each of the following 5-digit integers is a palindrome: 12322, 44444, 54345, 45554, and 11511. Write a Java program that reads in n (input from the user) five-digit integers and: Outputs the numbers into separated individual digits. Determines whether or not each number is a palindrome. Palindrome finder program. How many times testing for palindrome? 3 Enter a 5-digit number; 12345 The digits are: 1 2 3 4 5 This number is not palindrome. Enter a 5 -digit number; 12321 The digits are: 1 2 3 2 1 This number is not palindrome. Enter a 5-digit number; 11111 The digits are: 1 1 1 1 1 This number is not palindrome. Solution Palindrome.java import java.util.Scanner;//package for keyboard inputting class Palindrome{ //main class public static void main(String args[]){//main method int r,sum=0,temp; //variables Scanner sc=new Scanner(System.in); System.out.println(\"How many times you want to test\"); int nooftests=sc.nextInt();//keyboard inputting for(int k=0;k ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous