Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Java4

The document contains a Java program that identifies and prints palindrome numbers within a specified range. It defines a method to check if a number is a palindrome and uses a loop to iterate through the range provided by the user. The output displays all palindrome numbers between the starting and ending numbers entered by the user.

Uploaded by

121pratham2032
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java4

The document contains a Java program that identifies and prints palindrome numbers within a specified range. It defines a method to check if a number is a palindrome and uses a loop to iterate through the range provided by the user. The output displays all palindrome numbers between the starting and ending numbers entered by the user.

Uploaded by

121pratham2032
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3. Write a program to print palindrome number.

import java.u l.Scanner;

public class PalindromeNumber {

public sta c boolean isPalindrome(int num) {

int originalNum = num, reverse = 0, remainder;

while (num > 0) {

remainder = num % 10;

reverse = (reverse * 10) + remainder;

num /= 10;

return originalNum == reverse;

public sta c void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the star ng number: ");

int start = scanner.nextInt();

System.out.print("Enter the ending number: ");

int end = scanner.nextInt();

System.out.println("Palindrome numbers between " + start + " and " + end + " are:");

for (int i = start; i <= end; i++) {

if (isPalindrome(i)) {

System.out.print(i + " ");

scanner.close();

}
O/P: Enter the star ng number: 1

Enter the ending number: 121

Palindrome numbers between 1 and 121 are:

1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 101 111 121

You might also like