java中如何用scanner實現輸入數據?
java中Scanner類常用來進行數據的輸入。
Scanner 類在java.util包中。
操作實例:
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print("imput name:");
String name = sc.nextLine();
System.out.print("input age:");
int age = sc.nextInt();
System.out.print("input height:");
float height = sc.nextFloat();
System.out.print("name:" + name + "\n" + "age:" + age + "\n" + "height:" + height);
}
}
輸出結果如下圖:
下一篇Java安裝后怎么使用