7.20.10 用户输入

 
import java.util.Scanner;
 
class  InputDemo
{
public static void main(String[] args) 
{
// 1. 创建Scanner类的对象,这个对象从控制台读取用户的输入的内容
Scanner sc = new Scanner(System.in);
 
/*
// 读取整数 浮点数 布尔型
// 2. 打印信息,提示一下用户准备输入什么内容
System.out.print("请输入一个数(1-7):");
// 3. 读取用户的输入的内容
int week = sc.nextInt();// nextByte() nextShot() nextLong() nextFloat() nextDouble() nextBoolean()
// 4. 输出一下看看。
System.out.print("用户输入的是"+week);
 
// 2. 读取字符串
System.out.print("请输入字符传:");
String str = sc.next();
System.out.println("输入的字符串:"+str);
char c = str.charAt(0);
System.out.println("第一个字符是:"+c);
*/
 
int year,month,day;
System.out.print("请输入年份:");
year = sc.nextInt();
System.out.print("请输入月份:");
month = sc.nextInt();
System.out.print("请输入日期:");
day = sc.nextInt();
 
System.out.println("用户输入的是"+year+"-"+month+"-"+day);
 
}
}
posted @ 2017-08-24 13:34  ~~晴天~^.^  阅读(93)  评论(0编辑  收藏  举报