Question
Java Program A Palindrome is a word (or a number) that reads the same backwards. In this assignment you will be writing a program that
Java Program
A Palindrome is a word (or a number) that reads the same backwards. In this assignment you will be writing a program that repeatedly prompts a user for a positive integer number and tests whether the number is a palindrome. Your program should convert the integer value given by the user into an int array storing each digit of the number in the appropriate element of the array. It should then check to see whether the array is a palindrome. Your program should follow the guidelines given below.
1. Write a method called getSize( int num ) that takes an integer number as input argument and returns the number of digits in that number. For e.g., getSize( 234 ) should return 3 and getSize( 76 ) should return 2.
2. Write a method called fillArray( int num, int[] intArray ) that takes an integer number and an integer array argument and fills the array with the appropriate digits of the number. For e.g., calling the above method fillArray( 87432, intArray ) would set intArray[0] to the value 8, intArray[1] to 7, ..., and intArray[4] to 2.
3. Write a boolean method called isPalindrome( int[] intArray ) that takes an integer array argument and returns the value true if the array is a palindrome else returns false.
4. Finally, write the main method that prompts the user repeatedly for an integer number, uses the getSize method to find out the number of digits in that number, allocates the int array for that size, calls the method fillArray to populate the array with the digits of the number, calls the isPalindrome method to find out whether the array is a palindrome, and prints out the result. Your program should terminate when the user enters -99.
Notes: 1. In Java you can allocate an array using a variable for the size, i.e., int[] intArray = new int[size]; where size is an int variable. 2. You SHOULD NOT use any methods from either the String or the Arrays class in your program.
Name your source code Hw5.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started