Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

INSY 3300/5309 - HW #5

mmanny243
mmanny243 


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. 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. Note that the maximum value a user can enter is 2147483647, as that is the maximum int value that a variable can store. 3. You SHOULD NOT use any methods from either the String or the Arrays class in your program. You should name the source code file Hw5.java. Attachments
Tags
Clarifications

Answers

INSY 3300/5309 - HW #5 - Solution

mariobeka
mariobeka 



Here is provided the solution for the HW5. I have made comments throughout the code for better understanding. Attachments
HW5.java (2 K) Download Preview
num) { return (int) (Math.log10(num) + 1); } /** * Fill in an array with the digits of a number. * * @param num the number. * @param intArray the array to be filled. */ public void fillArray(int num, int[] intArray) { int [] numbers = getDigitsOf(num); for (int i

Screenshots
Purchase Answer

INSY 3300/5309 - HW #5 (Palindrome Test)

uetian_cute
uetian_cute 



The code for problem and a screenshot included. Attachments
Palindrome.zip (15 K) Download
Preview

Preview
integer value"); Scanner in =new Scanner(System.in); int num = in.nextInt(); while (num!=-99) { int array[]=new int[getSize(num)]; fillArray(num,array); if(isPalindrome(array)) { System.out.println("The number "+num+" is a palindrome"); } else {System.out.println("The number "+num+" is not a palindrome");} System.out.println("Enter an integer

Screenshots
Screenshot
Purchase Answer