Java編程:求一個字串的長度:使用鍵盤任意輸入一個字串, 輸出字串的長度。(例如鍵盤輸入:123abd,輸出:字串 長度為6)
uj5u.com熱心網友回復:
這東西都要發帖求助,不建議敲代碼喲,這種隨便百度一大堆uj5u.com熱心網友回復:
百度過了,都不符合要求,沒有找到合適的,
uj5u.com熱心網友回復:
太過簡單了吧?估計網上都沒人會問,基礎中的基礎啊,兄弟。
public class test3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("請輸入一個字串");
String str=sc.nextLine();
System.out.println("輸入的字串長度為:"+str.length());
}
}
uj5u.com熱心網友回復:
樓上的答案在往類名的上一行加一個 impore java.util.Scanner;uj5u.com熱心網友回復:
import java.util.Scanner;
/*
Java編程:求一個字串的長度:使用鍵盤任意輸入一個字串, 輸出字串的長度。(例如鍵盤輸入:123abd,輸出:字串 長度為6)
*/
public class Test01 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("請輸入字串:");
System.out.println("長度為:" + sc.next().length());
}
}
uj5u.com熱心網友回復:
把字串賦值給一個String型別的變數(如str),然后輸出該變數值額長度:System.out.println(str.length());轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/47839.html
標籤:Eclipse
上一篇:linux java創建檔案
下一篇:什么是glob
