Scanner的使用
步骤:
- 引入扫描仪:
import Java.util.Scanner;
- 创建扫描仪:
Scanner input = new Scanner(System.in);
- 获取键盘输入的数据:
int i = input.nextInt();
编程要求
从控制台接受输入来描述嫦娥的姓名、年龄、性别、体重、地址、婚否等信息,效果如下图:
package javaDemo;
import java.util.Scanner;
public class scanner<age, name> {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("请录入嫦娥个人信息:");
System.out.print("请输入姓名:");
String name = input.next();
System.out.print("请输入年龄:");
int age = input.nextInt();
System.out.print("请输入性别:");
String sex = input.next();
System.out.print("请输入体重:");
double weight = input.nextDouble();
System.out.print("请输入地址:");
String arr = input.next();
System.out.print("请输入是否已婚:");
String marr = input.next();
System.out.print("信息如下:");
System.out.println("\t姓名:"+name);
System.out.println("\t年龄:"+age+"岁");
System.out.println("\t性别:"+sex);
System.out.println("\t体重:"+weight+"kg");
System.out.println("\t地址:"+arr);
System.out.println("\t婚否:"+marr);
}
}