Chrome File Edit View History Bookmarks People Window Help 8

Chrome File Edit View History Bookmarks People Window Help 8 4))) 20% D Wed Nov 9 11 30 48 AM a E Lab Assignments Mod 6-Ch6 Programming Principles l Section 16 Fall Semester 2016 CO kennesaw.view.usg.edu 10367 4/fullscreen/18397105/View Page 1 of 2 Rectangle Width 4.0 Rectangle Length 5.5 Rectangle Area 11.52 Program 4 Design and implement a Java program for programming exercise 6.3, page 234 (name it PalindromInteger), to check if an integer value is a palindrome or not, using 2 methods (reverse and is Palindron) specified in the problem statement. Follow the instructions in the problem statement. Design the main method of your program such that it allows the user to re-run the program with different inputs e., use a loop structure). Document your code, and organize and space the outputs properly using escape characters Program 5 View as Tex

Solution

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be \"Main\" only if the class is public. */
public class HelloWorld
{
public static int reverse(int number){
int r,rev=0,temp;
while(number>0){
r=number%10;
number=number/10;
rev=rev*10+r;
}
return rev;
}
public static boolean isPallindrome(int number){
int rev= reverse(number);// returns reverse of a number
if(number==rev)
return true;
else
return false;
}

public static void main(String[] args)
{
int num;
   int flag=1;
   while(flag==1){// loop for taking input from user.
       Scanner sc=new Scanner(System.in);
       System.out.println(\"Do you want to check for pallindrome if yes enter \'1\' else \'0\' \");
flag=sc.nextInt();
System.out.println(\"Enter the number\");
num=sc.nextInt();
  
isPallindrome(num);// calling a function to check if number is pallindrome
   }
}
}

 Chrome File Edit View History Bookmarks People Window Help 8 4))) 20% D Wed Nov 9 11 30 48 AM a E Lab Assignments Mod 6-Ch6 Programming Principles l Section 16

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site