THINK FIRST·CODE LATER

← All labs

Palindromic numbers with methods

Problem

Write Palindromes with three methods: reverse(int n) returns n with its digits reversed, isPalindrome(int n) uses reverse, and digitCount(int n) counts digits. In main, read a range from to and print how many palindromes it contains, the largest one with its digit count, and reverse(to):

Palindromes between 100 and 200: 10
Largest: 191 (3 digits)
reverse(200) = 2

Each method must do one job and contain no printing.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

l8-3-data-1.txt

100 200
What your program must print for l8-3-data-1.txt
Palindromes between 100 and 200: 10
Largest: 191 (3 digits)
reverse(200) = 2

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < l8-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content l8-3-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.