Page Contents
Interview Content
- C Programming Coding Questions
- C Pattern Programming Questions
- C Programming Interview Questions
- Java Programming Coding Questions
- Java Pattern Programming Questions
- Java Programming Interview Questions
- Python Programming Coding Questions
- Python Pattern Programming Questions
- Python Programming Interview Questions
- SQL Interview Questions
Palindrome Program in Java using Iteration
Ans:
In this tutorial you will learn how to write a program in Java to check a given number is palindrome or not using iteration.
Before moving directly on the writing the program
Read this: What is Palindrome Number? Write a palindrome program in C.
How our Java program will behave?
Our program will take a number as an input to check given number of.
Suppose if someone gives an input 121 then our program should print “the given number is a palindrome”.
And if someone given input 123 the our program should print “the given number is not a palindrome number”.
Java program for palindrome number using iterative method
import java.util.*;
class Main{
public static void main(String ...args){
int tempvar,remainder,reverseNum=0;
Scanner sc= new Scanner(System.in);
System.out.print("Enter number- ");
int originalNum= sc.nextInt();
tempvar = originalNum;
while (tempvar != 0) {
remainder = tempvar % 10;
reverseNum = reverseNum * 10 + remainder;
tempvar /= 10;
}
if (originalNum == reverseNum)
System.out.print("Number is palindrom");
else
System.out.print("Number is not palindrom");
}
}
Output:
Also prepare these Java Programs:
- Java Program to print Fibonacci series using recursive method
- Palindrome program in Java for number using Recursive method
- Java program to check a given is an Armstrong
- Java program to add two numbers without using addition operator
- How to remove a character from a string in java
- Write a program in Java to count occurrence of a given character in a String.
- Java program to find largest and smallest number in an array
- Java program to print first duplicate number in an array of 1-100
- Java Program to remove duplicate elements from an array
- Program to count repeated elements in an array java
Latest Uploads on Website
- AVL Tree with explanation
- Radix sort algorithm explanation with example
- Quick Sort Algorithm with explanation
- Bubble sorting algorithm with Bubble sort program in C
- Insertion sort algorithm and program in C
- Selection Sort Algorithm and Program in C
- Linear probing technique explanation with example
- Collision in Hashing and Collision resolution technique
- Hashing in data structure with its types
- Binary search tree operations with Program
- Binary search tree in data structure
- Binary search algorithm in data structure with explanation
- linear search in data structure with Algo and Program