當前位置:編程學習大全網 - 編程軟體 - 用java將壹個字符串str的內容顛倒過來,並輸出。str的長度不超過100個字符 如:student 轉換為:tneduts

用java將壹個字符串str的內容顛倒過來,並輸出。str的長度不超過100個字符 如:student 轉換為:tneduts

public static void main(String[] args) {

Scanner rd;

String str;

do {

System.out.println("請輸入字符(長度小於100)");

rd=new Scanner(System.in);

str=rd.nextLine();

} while(str.length() > 100);

StringBuilder rts=new StringBuilder();

for(int i=str.length(); i > 0; i--) {

rts.append(str.charAt(i - 1));

}

System.out.println("顛倒過來:" + rts.toString());

}

  • 上一篇:麥格米特plc如何寫自鎖程序
  • 下一篇:華碩筆記本玩遊戲FPS值很低,遊戲也卡。怎麽解決?
  • copyright 2024編程學習大全網