Palindrome (Numbers) Program Using Java With I/O Stream

Introduction

In this blog, I will explain about Palindrome (Numbers) program, using Java. It is very simple in Java Programming. The output will be displayed in the Run module.

Software Requirement

JDK1.3.

Simple Program

  1. import java.io.*;  
  2.   
  3. class palind  
  4.  {  
  5.   public static void main(String arg[]) throws IOException   
  6.    {  
  7.      DataInputStream dr = new DataInputStream(System.in);  
  8.       
  9.      System.out.println("Enter the Number : ");  
  10.   
  11.      int no = Integer.parseInt(dr.readLine());  
  12.   
  13.      int d,r,a;  
  14.   
  15.      r=0;  a=no;  
  16.   
  17.      while(no!=0)  
  18.       {  
  19.        d = no%10;  
  20.   
  21.        r = r*10+d;  
  22.   
  23.        no = no/10;  
  24.       }  
  25.   
  26.      if(a==r)  
  27.        System.out.println("The given Number is Palindrome");  
  28.   
  29.      else   
  30.        System.out.println("The given Number is Not Palindrome");  
  31.   
  32.    }  
  33.   }    
Explanation

In this blog, I explained about Palindrome (Numbers) program, using Java. The output will be displayed in the Run module.

Output

 
Ebook Download
View all
Learn
View all