* scanner语法:
* 从键盘上依次输入byte int short long boolean 数据类型以及字符串
* 注:String不属于数据类型
*/
System.out.println("请输入byte类型:");
Scanner sc=new Scanner(System.in);
byte bytenum=sc.nextByte();
System.out.println(bytenum);
System.out.println("请输入int类型:");
int intnum=sc.nextInt();
System.out.println(intnum);
System.out.println("请输入short类型:");
short shortnum=sc.nextShort();
System.out.println(shortnum);
System.out.println("请输入long类型:");
long longnum=sc.nextLong();
System.out.println(longnum);
System.out.println("请输入double类型:");
double doublenum=sc.nextDouble();
System.out.println(doublenum);
System.out.println("请输入float类型:");
float floatnum=sc.nextFloat();
System.out.println(floatnum);
System.out.println("请输入布尔类型:");
boolean booleannum=sc.nextBoolean();
System.out.println(booleannum);
System.out.println("请输入字符串:");
String stringnum=sc.next();
System.out.println(stringnum);
Scanner语法:(纯代码例子)
最新推荐文章于 2024-03-10 20:10:02 发布