Question
Need help with JAVA code, completed assignment but need comparison as code is not successfully running. JAVA-jdk using Itellij Write a program that generates all
Need help with JAVA code, completed assignment but need comparison as code is not successfully running. JAVA-jdk using Itellij
Write a program that generates all 3 and 4-digit palindromes. You will copy your code from the 99A (before the extra credit) and put it into 66B as your starting point. A palindrome is a number that is the same backwards as it is forwards. You will write another static method called isPalindrome which will accept an integer parameter called original and will test whether original is equal to reversedDigits(original). If this is true, it will return true; if not, it will return false. In the output, you will neatly print 10 palindromes per line.
Objectives:
-To learn to use a method that returns a Boolean type
-To gain more experience with Booleans
-To gain more experience with a for-loop
-To learn to align numbers using a format specifier
-To learn to print a specific number of items per line using a counter and/or the mod (%) operator
1. Call your class Program66B, so your filename will be Program66B.java. It is essential for grading purposes that everyone have the same class name.
2. Use comments liberally to document exactly what you are doing in the program.
3. Use descriptive variable names in camel-case with the first letter in lowercase.
4. Copy the reverseDigits and the main methods from Program6A as it was BEFORE you added the extra credit part.
5. Add another method called isPalindrome. It should accept an int parameter called original and will return a Boolean. You only need one statement in it. You only need to return the value that you get when you compare original to reverseDigits(original). You don't need to set up a Boolean variable unless you really want to, but that will take more lines of code: return (original == reverseDigits(original));
6. In your main method, after your current output statement, add another line that prints the value of isPalindrome(original).
7. Get that working before proceeding. Copy it as a backup in case you mess up in the later steps.
8. Comment out the lines where you are asking and getting output from the user.
9. Set up a for-loop with i going from 1 to 100 in the beginning (youll change these limits later, but in the beginning, you should keep it small for testing purposes).
10. Inside the loop, see if i is a palindrome by saying if isPalindrome(i). If this is true, print it; if not, you dont do anything.
11. Get this working right before proceeding. Make a backup copy.
12. Figure out how to print 10 items per line. Youll need to set up a counter that adds one to it every time you print a palindrome, and youll reset it to zero after you print your 10th palindrome of that line. Be sure to line up your numbers, justified right, as shown in the sample run. (See Listing 6.7 on pages 218-219 in your Liang book, 11th Edition. In this example in the printPrimeNumbers method, they are printing numbers that pass the isPrime test, just like we want to print the numbers that pass the isPalindrome test.)
13. Get all of that working with a low limit first. Then youll need to change your limits on the for loop to handle 3 and 4-digit numbers instead of going from 1 to 100. Ask yourself, what is the lowest 3-digit number and the highest 4-digit number? Those will be your new limits.
Sample Runs:
101 111 121 131 141 151 161 171 181 191 202 212 222 232 242 252 262 272 282 292 303 313 323 333 343 353 363 373 383 393 404 414 424 434 444 454 464 474 484 494 505 515 525 535 545 555 565 575 585 595 606 616 626 636 646 656 666 676 686 696 707 717 727 737 747 757 767 777 787 797 808 818 828 838 848 858 868 878 888 898 909 919 929 939 949 959 969 979 989 999 1001 1111 1221 1331 1441 1551 1661 1771 1881 1991 2002 2112 2222 2332 2442 2552 2662 2772 2882 2992 3003 3113 3223 3333 3443 3553 3663 3773 3883 3993 4004 4114 4224 4334 4444 4554 4664 4774 4884 4994 5005 5115 5225 5335 5445 5555 5665 5775 5885 5995 6006 6116 6226 6336 6446 6556 6666 6776 6886 6996 7007 7117 7227 7337 7447 7557 7667 7777 7887 7997 8008 8118 8228 8338 8448 8558 8668 8778 8888 8998 9009 9119 9229 9339 9449 9559 9669 9779 9889 9999
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