Computer Science, asked by 1411941arjun, 5 hours ago

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sn=new Scanner(System.in);
System.out.print("enter the word: ");
String str=sn.next();
String org=str;
int ln =org.length();
String rev=" ";
for (int i=ln-1;i>=0;i--)
{
rev=rev + str.charAt(i);
}
System.out.println(rev);

if (org.equals(rev))
{
System.out.println("it is a palindrome");

}else
{
System.out.println("no it is not a palindrome");
}
}
}

i don't know why it print (if part )with else part in the output pls someone tell me​

Answers

Answered by avanishyadav16
7

Explanation:

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner sn=new Scanner(System.in);

System.out.print("enter the word: ");

String str=sn.next();

String org=str;

int ln =org.length();

String rev=" ";

for (int i=ln-1;i>=0;i--)

{

rev=rev + str.charAt(i);

}

System.out.println(rev);

if (org.equals(rev))

{

System.out.println("it is a palindrome");

}else

{

System.out.println("no it is not a palindrome");

}

Similar questions