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中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);
}
}
輸出結果如下圖: