1. 程式人生 > >ProgrammingProjectList-文本操作

ProgrammingProjectList-文本操作

lin stat obb github ring println builder () ava

https://github.com/jobbole/ProgrammingProjectList

  • 逆轉字符串——輸入一個字符串,將其逆轉並輸出。
    package com.zrl.github;
    import java.util.Scanner;
    public class ReverseString {
        public static void main(String[] args) {
            Scanner cin = new Scanner(System.in);
            System.out.println("請輸入一個字符串:");
            
    while(cin.hasNext()) { StringBuilder sb = new StringBuilder(cin.nextLine()); //定義可變長的線程不安全字符串 //sb.reverse(); String sb1 = ""; int n = sb.length(); for(int i=0; i<n; i++) { char x = sb.charAt(n-i-1); sb1
    += x; } System.out.println("輸出逆轉後的字符串:" + sb1); System.out.println("請輸入一個字符串:"); } } }

ProgrammingProjectList-文本操作