Question

write a program that prints the palindromic numbers (in decimal ) between 0-9999 into the screen....

write a program that prints the palindromic numbers (in decimal ) between 0-9999 into the screen.

Note :it should be written in java language.

Homework Answers

Answer #1

Answer:

Here is the code, the explanation is in the comments. Please go through them for better understanding of the code. All you need to do is to create a class called PalindromeRange.java, paste the below code and execute. Please do not hesitate to leave a comment if you don't understand the code. Good Luck!!!

PalindromeRange.java

public class PalindromeRange { // Start of class

int isPalindrome(int number) { // check whether the number is palindrome

int originalNumber = number; // preserve the original number passed into the method for later comparison
int reverse = 0; // set reverse to 0 to start with

while(number != 0) { // until the number is not 0, loop in and keep dividing the number
int remainder = number % 10; // do the modulus division on the number
reverse = reverse * 10 + remainder; // keep adding the remainders
number /= 10; // perform regular division
}
if (originalNumber == reverse){ // if the original number and reversed numbers are equal, then return 0
return 0;
}else {
return 1; // if original number and reversed numbers are not equal, return 1
}
}
void range(int startRange, int endRange) // This is the method where you display the palindrome numbers
{
for (int i = startRange; i <= endRange; i++) { // Start a for loop 0-9999
if (isPalindrome(i) == 0){ // call the isPalindrome() in the for loop
System.out.print(i + " "); // Display the palindrome numbers
}
}
}
public static void main(String [] args) { // Start of main()

PalindromeRange palindromeRange = new PalindromeRange(); // Create an obj of PalindromeRange()
palindromeRange.range(0, 9999); // call the method range()

} // End of main()
} // End of class

O/P Screenshot for your reference


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a program that prints all palindromic numbers between 0-9999 into the screen. Note :The code...
write a program that prints all palindromic numbers between 0-9999 into the screen. Note :The code should be written in java language.
Using for loops: - write a Java program that adds numbers between 1 to 100 and...
Using for loops: - write a Java program that adds numbers between 1 to 100 and prints the result. - write a Java program that adds odd numbers between 1 to 100 and prints the result - write a Java program that averages even numbers between 5 to 30 and prints the result
- Write a python program which prints all the numbers between 1 and 100 that are...
- Write a python program which prints all the numbers between 1 and 100 that are divisible by 3.
Write a program with while loop that prints all numbers between 5 and 100 (inclusive) that...
Write a program with while loop that prints all numbers between 5 and 100 (inclusive) that are divisible by 5.
Write an assembly language program that prints your full name on the screen. Use .ASII pseudo-op...
Write an assembly language program that prints your full name on the screen. Use .ASII pseudo-op to store the characters at the top of your program Use BR to branch around the characters and use STRO to output your name. Comment each line except STOP and .END. Cut and paste the Assembler Listing into your document Paste a screen shot of the Output area of the Pep8 program Please use the name "Levin Fi" Assembler Listing Screen Shot of the...
Write a program that finds and prints all of the prime numbers between 3 and X...
Write a program that finds and prints all of the prime numbers between 3 and X (X is input from the user). A prime number is a number such that 1 and itself are the only numbers that evenly divide it (for example, 3, 5, 7, 11, 13, 17, …). One way to solve this problem is to use a doubly nested loop (a loop inside another loop). The outer loop can iterate from 3 to N while the inner...
Write a program that asks the user to enter an odd number and prints out a...
Write a program that asks the user to enter an odd number and prints out a triangle pattern. For example, if the user enters 5, the output is note: There is one space between the numbers in each line 1 3 5 1 3 1 If the user enters 9 the output is: 1 3 5 7 9 1 3 5 7 1 3 5 1 3 1 program language: C++
Write a program in python that prints the count of all prime numbers between A and...
Write a program in python that prints the count of all prime numbers between A and B (inclusive), where A and B are defined as follows: A = The 5 digit unique number you had picked at the beginning of the semester B = A + 5000 Just a recap on prime numbers: A prime number is any number, greater or equal to 2, that is divisible ONLY by 1 and itself. Here are the first 10 prime numbers: 2,...
Java Write a program that prints the letters corresponding to the numbers on the telephone. So...
Java Write a program that prints the letters corresponding to the numbers on the telephone. So if you were to enter 6 it should print MNO. Now since you do not know how to do a System.in just do you for the number 7. So your code should be like int numberEntered = 7; String value; swtich (numberEntered){ case 1: value = "Nothing definded for 1"; break; case 2 : value = "A,B,C"; break ..... ..... default: value = "Not...
Write a java program that prints the letters corresponding to the numbers on the telephone. So...
Write a java program that prints the letters corresponding to the numbers on the telephone. So if you were to enter 6 it should print MNO. Now since you do not know how to do a System.in just do you for the number 7. So your code should be like int numberEntered = 7; String value; swtich (numberEntered){ case 1: value = "Nothing definded for 1"; break; case 2 : value = "A,B,C"; break ..... ..... default: value = "Not...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT