Wednesday 2 December 2020

Palindrome Without User Interaction

Write a Java Program to Check Whether a Number is Palindrome or Not Without User Interaction  
public class ArrayPalindromeWithoutUserInteraction 
{
	public static void main(String[] args) 
	{
	int arrNumbers[] = new int[] {1441, 65, 22, 87, 121, 96358, 159951};	
	System.out.println("Array is\n{1441, 65, 22, 87, 121, 96358, 159951}");
	for(int i=0 ; i<arrNumbers.length;i++)
	{
		int n = arrNumbers[i];
		int reverseN = 0;
		int reminde=0;				
		while(n>0)
		{
			reminde =n%10;
			n=n/10;
			reverseN=reverseN*10+reminde;
		}
		if(arrNumbers[i]==reverseN)
		{
		System.out.println("\n"+arrNumbers[i]+ "  is pallindrome" );
		}
		else
		{
		System.out.println("\n"+arrNumbers[i]+ "  is  not a pallindrome");
		}
	}
	}
}

Output
Array is
{1441, 65, 22, 87, 121, 96358, 159951}

1441  is pallindrome

65  is  not a pallindrome

22  is pallindrome

87  is  not a pallindrome

121  is pallindrome

96358  is  not a pallindrome

159951  is pallindrome


No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32