1.7.33 determines whether the NOI string palindrome

Description
enter a string to the output string if palindrome. Palindrome refers to read and read backwards along the same string.

Input
input line string (not whitespace, the string length does not exceed 100).
Output
If the string is a palindrome, output yes; otherwise, output no.
Sample input
abcdedcba
Sample Output
yes

solution:

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner in=new Scanner(System.in);
	String a=in.nextLine();
	char b[]=a.toCharArray();
	char c[]=new char[b.length];
	for(int i=b.length-1;i>=0;i--) {
		c[b.length-1-i]=b[i];
	}
	String c1=String.valueOf(c);
	if(c1.equals(a)) {
		System.out.println("yes");
	}
	else {
		System.out.println("no");
	}
	}
}
Published 79 original articles · won praise 68 · views 1804

Guess you like

Origin blog.csdn.net/weixin_45455503/article/details/104559324