Java学习day03_键盘输入

2021/4/12 22:55:13

本文主要是介绍Java学习day03_键盘输入,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 1 package com.Diyi.day01;
 2 
 3 import java.util.Scanner;  //导入的文件夹
 4 
 5 public class Lishuai06_键盘录入 {
 6     public static void main(String[] args) {
 7         System.out.println("请输入:" );
 8         Scanner sc = new Scanner(System.in);        //定义Scanner类变量 sc 为Scanner类的示例
 9         int a = sc.nextInt();                  //定义的类类型的变量称为对象
10         String name = sc.next();
11         double  c = sc.nextDouble();
12         System.out.println("整型:"+a);
13         System.out.println("字符串类类型:"+ name);
14         System.out.println("浮点型:" + c );
15         
16         if(false)
17         {
18             new/*新建一个文件*/ Scanner/*属于scanner类*/(System.in/*参数*/).nextInt/*函数*/();   
19 // scannner在别的包下,需要在类上方&包下方  引用import    scanner类所在的文件,文件叫做java.util.Scanner
20             // new Scanner(System.in);   这个指令目的就是  创建Scanner类的对象/示例
21             //.nextInt         调用类里面的针对整数的函数
22         }else
23         if(false) {
24         System.out.println("输入值:" );
25         int  b = new Scanner(System.in).nextInt();  //nextInt  nextDouble   nextChar  nextBoolean等
26 //        System.out.println("输入值:" );
27         System.out.println(a);
28         }
29         
30     }
31 
32 }
 1 package com.Diyi.day01;
 2 
 3 public class LiShuai03_算数运算符1 {
 4     //算术运算符包括  1.加减乘除运算符  2.取余运算符  3.关系运算符
 5     public static void main(String[] args) {
 6     int price = 8;
 7     int a = 5;
 8     double weight = 2.5;
 9     double money = price*weight;
10     System.out.println("money" + money);
11     System.out.println();
12     
13     
14     }
15 }
16 class LiShuai_自增运算符{
17 //    public static void main(String[] args) 
18     {
19         int b = 15;
20         System.out.println(b++);
21     }
22     
23 }
自增运
 1 package com.Diyi.day01;
 2     //       true?正确要的结果:错误要的结果
 3 public class Lishuai04_三元运算符 {
 4 
 5     public static void main(String[] args) {
 6     System.out.println(3>2?100:200);
 7 
 8     }
 9 
10 }
三元运算符
 1 package com.Diyi.day01;
 2 
 3 public class LiShuai04_自增运算符 {
 4     public static void main(String[] args) {
 5         /*
 6          * ++  --  
 7          * +=    -=  *=        /=        %=
 8          * 
 9          * 
10          * */
11                 int b = 15;
12                 int c = b++;                //b赋值给c,然后b++
13                 int f = ++b;                   //b++直接赋值给f
14                 int d = 15;
15                 int e = ++d;
16                 System.out.println(c);
17                 System.out.println(b);
18                 System.out.println(f);
19                 System.out.println(e);     
20                 
21                 b -= b;                        // 2b
22                 c += d;        // c = c+d
23                 int r =c;
24                  r %= 2;
25                 System.out.println(b);
26                 System.out.println(c);  
27                 System.out.println(r);
28                 
29                 int g = 10;     // 两值互换
30                 int h = 11;
31                 int temp;
32                 temp = g;
33                 g = h;
34                 h = temp;
35                 System.out.println(g);
36                 System.out.println(h);
37                 System.out.println(temp);
38             }
39     }
40     
自增运算符1
 1 package com.Diyi.day01;
 2 
 3 public class Lishuai05_if语句 {
 4     public static void main(String[] args) {
 5         int a = 15,b = 90,c = 100;
 6         if(false) {                       //if(false) 不访问{} 里的语句;        if语句后没有{},只控制一行
 7             System.out.println(999);                 //一行指令
 8         }
 9         if(a>b)
10             {
11                 System.out.println(888);
12             }
13         else
14             {
15                 System.out.println(999);
16             }
17         if(2021%4 ==0)
18         {
19             System.out.println("闰年");
20         }
21         else {
22             System.out.println("平年");
23         }
24         
25     }
26 
27 }
if语句

 

算符

  

 1 package com.Diyi.day01;
 2 /**
 3  * 
 4  * 比较运算符包括   ==  >  <   <=  >=  !=
 5  *
 6  */
 7 public class Lishuai04_比较运算符 {
 8     public static void main(String[] args) {
 9         int a = 3;
10         int b = 13;
11         int c = 13;
12         System.out.println(a == b);
13         System.out.println(a >= b);
14         System.out.println(b == c);
15         System.out.println(a <= b);
16         System.out.println(a != b);
17         System.out.println(b != c);
18         
19     }
20 
21 }
比较运算符

 



这篇关于Java学习day03_键盘输入的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程