Access over 35 million academic & study documents

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\");

Sign up to view the full document!

lock_open Sign Up
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 \");

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/4

Sign up to view the full document!

lock_open Sign Up
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
Great! 10/10 would recommend using Studypool to help you study.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4