王治騰Java方法length(), charAt(), EXCEL函數LEN, MID 12月 25, 2022

w3schools練習Java length(), charAt()

原本錯誤範例
訂正後範例

運用 VS Code

Java程式碼

public class Main {   /*王治騰2022.12.26 德明財金一甲*/
  public static void main(String[] args) {
    String a = "阿囉哈", b="";
    System.out.println("原來:"+a) ;
    int c = a.length(); /*方法length()*/
    System.out.println("長度:"+c) ;
    for (int i = 0; i < c; i++)  /*迴圈*/
      b = a.charAt(i) + b;  /*一個個字元接到前面,變成反向*/
    
    System.out.println("反向 "+ b);
  }

留言

熱門文章