Skip to content

Instantly share code, notes, and snippets.

@969rishi
Last active September 28, 2023 22:22
Show Gist options
  • Save 969rishi/30b03d7bbbf63b3b01cb6c2c2926d181 to your computer and use it in GitHub Desktop.
Save 969rishi/30b03d7bbbf63b3b01cb6c2c2926d181 to your computer and use it in GitHub Desktop.
Palindrome number solution Program in Java by Rishi
/******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.ArrayList;
public class Main
{
public static void main (String[]args)
{
int num = 34543;
int originalNum = 0;
int reverseInt = 0;
ArrayList < Integer > myNum = new ArrayList <> ();
originalNum = num;
// System.out.println ("modulas of " + num + " = " + num % 10);
// System.out.println ("devision of " + num + " = " + num / 10);
while (num > 0)
{
myNum.add (num % 10);
num = num / 10;
}
for (int i = 0; i < myNum.size (); i++)
{
// System.out.println ("Array of " +myNum.get(i));
reverseInt = reverseInt * 10 + myNum.get (i);
}
// System.out.println ("reverseInt " +reverseInt);
if (originalNum == reverseInt)
{
System.out.println (reverseInt +
" This is Palindrome number ✓✓✓");
}
else
{
System.out.println (reverseInt +
" This is NOT A Palindrome number XXX");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment