日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

回文java_回文 Java

發(fā)布時間:2025/4/17 94 豆豆
生活随笔 收集整理的這篇文章主要介紹了 回文java_回文 Java 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

package test.HWtest;

import java.util.Scanner;

public class HWString {//判斷字符串

public static void hwReverse(String str){//方法一;將字符串倒置后逐一比較,

StringBuffer sb =new StringBuffer(str);

//System.out.println(sb);

sb.reverse();

//System.out.println(sb);

String newStr =new String(sb);

if(str.equals(newStr)){

System.out.println("1是回文");

}

else{

System.out.println("1不是回文");

}

}

public static void hwlength(String str){

StringBuffer sb =new StringBuffer(str);

//System.out.println(sb);

sb.reverse();

//System.out.println(sb);

int count=0;

for(int i=0;i

//數(shù)組中有l(wèi)ength屬性,沒有l(wèi)ength()方法

if(str.charAt(i)==sb.charAt(i)){

count++;

}

}

if(count == str.length()){

System.out.println("2是回文");

}

else{

System.out.println("2不是回文");

}

}

public static void main(String[] args) { //方法二 將字符串倒置后創(chuàng)建新字符串直接比較,

// TODO Auto-generated method stub

Scanner sc =new Scanner(System.in);

String str ="";

str =sc.nextLine();

hwReverse(str);

hwlength(str);

/*iamai

1是回文

2是回文*/}

}

總結(jié)

以上是生活随笔為你收集整理的回文java_回文 Java的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。