劉任昌Java內建方法length(),charAt()

w3schools編寫Java程式語言

微軟VS Code編寫Java程式語言

Java程式語言

public class Main {/*劉任昌w3schools內建方法length,charAt*/
  public static void main(String[] args) {
    String a = "狗吃大便,貓抓鼠";
    String b = "";           /*字串b初始值是空的*/
    int c = a.length();      /*方法 length() 得到字串長度*/
    System.out.println("原來字串: " + a);
    System.out.println("字串長度: " + c);
    for (int i = 0; i < c; i++) 
      b = a.charAt(i) + b;   /*方法charAt()得到該位置的字元*/
    System.out.println("反向字串: "+ b);
  }
}

下次上課Java程式語言

import java.util.Scanner; // Import the Scanner class

class MyClass {
  public static void main(String[] args) {
    String a, b="";
    Scanner myObj = new Scanner(System.in); // Create a Scanner object
    System.out.print("輸入: ");
    a = myObj.nextLine(); // Read user input
    for (int i = 0; i < a.length(); i++)
        b = a.charAt(i) + b;
      System.out.println("輸出: "+ b);
    }
}

留言

  1. https://cindy-javascript.blogspot.com/2022/12/blog-post_22.html

    回覆刪除
  2. https://xdrcfvghyujiok8945656.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  3. https://tgyhjikolujik2554.blogspot.com/2022/12/blog-post_22.html

    回覆刪除
  4. https://iuytjhg5261.blogspot.com/2022/12/blog-post_22.html

    回覆刪除
  5. https://www.blogger.com/blog/post/edit/8816069461855785316/4141137867077338132

    回覆刪除
  6. https://rtytrdtfg.blogspot.com/2022/12/javalengthchatat.html

    回覆刪除
  7. https://yuzcc28.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  8. https://lihtml-css-javascript-java.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  9. https://www.blogger.com/blog/post/edit/5444106583314177344/692679455548677204

    回覆刪除
  10. https://unnnn20.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  11. https://d11150116.blogspot.com/2022/12/javalengthchatat.html

    回覆刪除
  12. https://wxxx17.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  13. https://d11150110.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  14. https://d11150108.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  15. https://d11150114.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  16. https://d11150115.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  17. https://d11150112.blogspot.com/2022/12/blog-post_22.html

    回覆刪除
  18. https://danny1219.blogspot.com/2022/12/public-class-main-w3schools.html

    回覆刪除
  19. https://www.blogger.com/blog/post/edit/4875050941750982933/7717410886791635101

    回覆刪除
  20. https://xylia-lin.blogspot.com/2022/12/javalengthvs-code.html

    回覆刪除
  21. https://jia-yi-lin.blogspot.com/2022/12/javalengthcharatvs-code.html

    回覆刪除
  22. https://eric-young92.blogspot.com/2022/12/javalengthcharat.html

    回覆刪除
  23. https://www.blogger.com/blog/post/edit/preview/2906555295508746076/3807910884841986512

    回覆刪除
  24. https://hsiehyuche.blogspot.com/2022/12/javalengthcharatexcellen.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

劉任昌對照Python與JavaScript指令

劉任昌Python集合set清單list元組tuple字典dictionary

劉任昌python, input, str, float