JAVA基本语法
从键盘输入
import java.util.Scanner;//导入包
class ScannerTest{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);//Scanner类的实例化
int num=scan.nextInt();
System.out.println(num);
}
}
import java.util.Scanner;//导入包
class ScannerTest{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);//实例化
System.out.println("请输入你的名字:");
String name=scan.next();
System.out.println(name);
System.out.println("请输入你的年龄:");
int age=scan.nextInt();
System.out.println(age);
System.out.println("请输入你的体重:");
double weight=scan.nextDouble();
System.out.println(weight);
System.out.println("你好吗?");
boolean isWell=scan.nextBoolean();
System.out.println(isWell);
//对于char型的获取,Scanner没有提供相关的方法,只能获取一个字符串
System.out.println("请输入你的性别:(男/女)");
String gender=scan.next();
char genderChar=gender.charAt(0);
System.out.println(genderChar);
}
}