import java.util.Scanner ;public class Huiwen {public static void main ( String [] args ) {Scanner input = new Scanner ( System . in );String huiwen ;char [] arr ;int i , j , len ;do {System . out . print ( "请输入字符串:" );huiwen = input . next ();arr = huiwen . toCharArray ();len = arr . length ;for ( i = 0 , j = len - 1 ; i < arr . length ; i ++, j --) {if ( arr [ i ] != arr [ j ]) {break ;}}if ( i >= j ) {System . out . println ( huiwen + " 是回文" );} else {System . out . println ( huiwen + " 不是回文" );}System . out . println ( "是否继续?(Y/N)" );String answer = input . next ();if (! answer . equalsIgnoreCase ( "y" )) {break ;}} while ( true );System . out . println ( "程序结束,谢谢使用!" );}}
对回文判断的代码
最新推荐文章于 2023-11-27 08:46:44 发布