Question: Problem Description : Palindromes are words or numbers that are read the same forwards and backwards. For example: 1, 2, 3, 4, 5, 6,




Problem Description : Palindromes are words or numbers that are read the same forwards and backwards. For example: 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55, 66, 77, 88, 99, 101, 111, 121 are palindrome numbers. Prime numbers are the numbers that are dividable by only one and by themselves. For example: 2, 3, 5, 7, 11, 13, 17, 19, 23 are prime numbers. Develop an algorithm and then translate it to a Java program to prompt user for an integer number, n. The program should print all prime palindrome numbers less than or equal to n. For example: 2, 3, 5, 7, 11, 101 are all palindrome prime numbers less than 102. Use top-down design, and divide the problem into appropriate sub-problems. You should develop following methods and use them in your program: Takes a positive integer number as it argument, and returns true if n is a prime number, otherwise returns false. public static boolean is_prime(int n) { } Takes a positive integer number as it argument, and returns true if n is a palindrome number, otherwise returns false. public static boolean is_palindrome(int n) { } Develop other methods that you need to finish your lab assignment. Notes: 1. The body of the main program should be very simple, and it should call appropriate methods to do the task. 2. We have not studied Strings and arrays yet, so you should not use them to solve this problem. 3. Design and develop numerical methods to solve the problem. 4. Use javadoc style comment and comment the class and methods. Part B: [10 marks] Develop body of the even2odd(int n) that takes an integer number as an argument and changes all even digits of the number to odd digits by adding one to each odd digit. The method should return the result as an integer number. The class Lab5B.java is partially developed. Develop body of the even2odd (int n) method. public class Lab5B{ public static void main(String [] args) { // Sample test case: int n=26540; System.out.println("n= System.out.println("n= } n=9528; "+n+", ans= "+even2odd (n)); "+n+", ans= "+even2odd (n)); Part B: [10 marks] Develop body of the even2odd(int n) that takes an integer number as an argument and changes all even digits of the number to odd digits by adding one to each odd digit. The method should return the result as an integer number. The class Lab5B.java is partially developed. Develop body of the even2odd (int n) method. } public class Lab5B{ public static void main (String[] args) { // Sample test case: int n=26540; System.out.println("n= System.out.println("n= } n=9528; /** } changes all even digits of argument to odd digits by adding 1 to each digits @param n: a positive integer number @return the result as an integer number */ public static int even2odd (int n) { "+n+", ans= "+even2odd (n)); "+n+", ans= "+even2odd (n)); int ans=0; //your goes here. return ans; examples for function call: n= 26540, ans= 37551 n= 9528, ans= 9539
Step by Step Solution
3.40 Rating (156 Votes )
There are 3 Steps involved in it
import javautilScanner public class PrimePalindrome public static boolean isprimeint n ... View full answer
Get step-by-step solutions from verified subject matter experts
