Java //使用scanner从键盘输入多种类型

 1 //1.引入包名   import java.util.Scanner
 2 //2.新建Scanner对象
 3     Scanner scan =  new Scanner(system.in);
 4  //3.调用使用的数据类型
 5      int score= scan.nextInt();
 6 
 7 
 8  //使用scanner从键盘输入多种类型
 9       System.out.println("请输入字符:");
10       Scanner sex = new Scanner(System.in);
11       String sexChar= sex.next();
12       char sexSex= sexChar.charAt(0);  //获取索引为0位置和上的位置
13       System.out.println(sexSex);
14 
15       
16       
17       
18       
19       
20       
21       
22       
23       
24      
25        System.out.println("输入您的分数:");
26        
27        Scanner score = new Scanner(System.in);
28        int num=score.nextInt();
29      
30         
31         
32        System.out.println("您的分数为:"+num);
33        
34       
35        if(num < 30 && num>=0)
36        {
37            System.out.println("不要了。扔了");
38        }
39        else if(num >=30 && num <60)
40        {
41            System.out.println("该打");
42        }
43        else if(num>= 60 &&num <80)
44        {
45            System.out.println("口头鼓励");
46        }
47        else
48        {
49            System.out.println("买车车");
50        }
51         
52       

 

 //数据类型

 

posted on 2021-08-27 17:06  Bytezero!  阅读(249)  评论(0编辑  收藏  举报