Computer Science, asked by Anonymous, 5 months ago


Write  \: a  \: program \:  to  \: accept  \: a \:  number  \: and \:  check \:  whether  \:    \\ the \:  number  \: is \:  a  \: pallindrom \:  or \:  not......
JAVA

Using scanner class ....

Don't spam.....​

Answers

Answered by samarthkrv
0

Answer:

import java.util.Scanner;

class palindrome

{

static String reverse(String s)

{

char[] letters = new char[s.length()];

 int ind = 0;

 for(int i = s.length() - 1; i >= 0; i--)

 {

 letters[ind] = s.charAt(i);

 ind++;

 }

 String reversed = "";

  for(int i = 0; i < s.length(); i++)

  {

  reversed = reversed + letters[i];

  }

return reversed;

}

static boolean isPalindrome(String str)

{

 if(reverse(str).equals(str))

 {

 return true;

 }

 else

 {

 return false;

 }

}

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter a string:");

String x = sc.nextLine();

 if(isPalindrome(x))

 {

 System.out.println(x + " is a palindrome");

 }

 else

 {

 System.out.println(x + " is not a palindrome");

 }

}

}

Explanation:

Similar questions