/*
如何从键盘获取不同类型的变量:需要使用Scanner类
1.导包:import java.util.Scanner;
2.Scanner的实例化:Scanner scan = new Scanner(System.in);
3.调用Scanner类的相关方法(next()/nextXxx()),来获取指定类型的变量。
import java.util.Scanner; class ScannerText{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); System.out.println("please input your name:"); String name = scan.next(); System.out.println(name); System.out.println("please input your age:"); int age = scan.nextInt(); System.out.println(age); System.out.println("please input your weight:"); double weight = scan.nextDouble(); System.out.println(weight); System.out.println("dou u love me?"); boolean isLove = scan.nextBoolean(); System.out.println(isLove); System.out.println("please input your sex:"); String gender = scan.next(); char genderChar = gender.charAt(0); System.out.println(genderChar); }}
标签:java,Scanner,scan,System,获取,println,your,输入,out From: https://www.cnblogs.com/emary/p/16709157.html