guyanqing 1 rok temu
rodzic
commit
a4e9c3c33f

+ 302 - 0
src/main/java/com/sf/day02/Test.java

@@ -0,0 +1,302 @@
+package com.sf.day02;
+
+
+import javax.swing.text.MaskFormatter;
+import java.util.Scanner;
+
+public class Test {
+    static int age = 18;
+
+
+
+
+    /*
+    获取用户的方法
+    方法名:getInfo
+    参数名称:args
+    形参   实参
+
+    参数类型:String[]
+     */
+    public void getInfo(String[] args){
+        System.out.println(args);
+//        System.out.println(age);
+    }
+
+    /**
+     * 静态方法  用 静态变量
+     * 非静态方法中  可以使用静态变量
+     * @param args
+     */
+    public static void main(String[] args) {
+
+
+        /**
+         * 随机数
+         *
+         */
+//        double random = Math.random();
+//        System.out.println(random);
+//        for (int i = 0;i<10;i++){
+//            double random = Math.random();
+//            System.out.println(random);
+//        }
+
+        /**
+         * [5   - 9]
+         */
+        for (int i = 0;i<100;i++){
+//            double v = (Math.random() * 5) + 5;
+//            System.out.println(v);
+            //  [103--118]  int
+            int v = (int) ((Math.random() * 16) + 103);
+            System.out.println(v);
+        }
+
+        /**
+         * [1,6] int    double(1,6)
+         */
+        for (int i = 0;i<100;i++){
+         //   [1,6] int   6.999909  --  int
+            int v = (int) ((Math.random() * 6) + 1);
+            System.out.println(v);
+            //double(1,6)   6.9999---5.9999
+            double v1 = ((Math.random() * 5) + 1);
+            System.out.println(v1);
+        }
+
+
+
+//        eat("饺子");
+//        eat("包子");
+//        System.out.println(age);
+//        /**
+//         * 变量
+//         * 格式: 数据类型  变量名  =  变量值
+//         */
+//
+//        int userId = 1001;
+//        int userId1;
+//        userId1 = 1002;
+//        //如果说 我定义两个变量   a = 10  b  = 11
+//        int a , b ;
+//        a = 10;
+//        b = 11;
+//        int a1 =10,b1 =11;
+//        int c = 0;
+////        System.out.println(a1);
+//        System.out.println(c);
+
+        /**
+         * 整型
+         * byte short int long
+         */
+
+//        byte a = 1;
+//        short b = 2;
+//        int c = 3;
+//        long d = 4L;
+//
+////        float e = 5.0F;
+//        float e = (float)5.0;
+//
+////        double sum = 1 + 1.0;
+//        double v = 1 + 1.0;
+//        /**
+//         * java中用来表示字符串的类型是String
+//         */
+//        String str = "abcd";
+//        System.out.println(str);
+//        double f = 5.0;
+//
+//        char ch = 'A';
+//        char c1 = '\n';
+////        System.out.println("a");
+////        System.out.print("a");
+//        //A =  65   a  = 97
+//
+//        System.out.println((int) ch);
+//
+//        char a1 = 'a';
+//        System.out.println((int) a1+ch);
+//        System.out.println((char) 107);
+//
+//        boolean flag = true; //真
+//        boolean flag1 = false;  //假
+
+        /**
+         * 在没有接收值的情况下   a++  和  ++a 等同效果    都是对a进行+1操作
+         */
+//        int a = 1;
+//        int b = 2;
+////        a++;
+//         ++a;
+//        System.out.println(a);
+
+        /**
+         * 在有接收值的情况下
+         * int c = a++;
+         * 先赋值在运算   a-->b     再对a的本身进行+1操作
+         *
+         * int b = ++a;
+         * 先运算后赋值      先对a的本身进行+1操作   再赋值给接受的变量值
+         */
+//        int a =1;
+////        int b = a++;
+//        int b = ++a;
+//        System.out.println(a);
+//        System.out.println(b);
+
+        short s = 3;
+        s= (short) (s+2);  //1   可能存在数据精度丢失问题
+        s += 2;  //2  推荐
+
+        long d = 2;
+        d = d+2;
+        d += 2;
+
+        /**
+         * | 运算符     | 介绍               | 范例                      | 结果  |
+         * | :--------- | :----------------- | :------------------------ | :---- |
+         * | !=         | 不等于             | 4!=3                      | true  |
+         * | ==         | 判断两个数是否相等 | 4==3                      | false |
+         * | <          | 小于               | 4<3                       | false |
+         * | >          | 大于               | 4>3                       | true  |
+         * | <=         | 小于等于           | 4<=3                      | false |
+         * | >=         | 大于等于           | 4>=3                      | true  |
+         * | instanceof | 检查是否是类的对象 | “Hello” instanceof String | true  |
+         */
+//        if(4 != 3){
+//            System.out.println(true);
+//            System.out.println(true);
+//        }
+//        else {
+//            System.out.println(false);
+//            System.out.println(false);
+//        }
+//
+//        boolean a = true;
+//        boolean b = false;
+//        if(a&&b){
+//            System.out.println("zhen");
+//        }
+//
+//        boolean c = false;
+//        if(c&&a){
+//            System.out.println("zhen");
+//        }
+//
+//        /**
+//         * 5< x >10(x大于5并且小于10)    3
+//         */
+//
+//        int x = 0;
+//        if(x >5  &&  x<10){
+//
+//        }
+////        int i = 5 >> 2;
+////        System.out.println("5<<2 ===="+ i);
+//        int num = 2;
+//        System.out.println(num<<2);
+//        System.out.println(num);
+//
+//        /**
+//         * 格式: (条件表达式)?表达式1:表达式2
+//         */
+//        int aa = 9;
+//        int bb = 8;
+//        int max = (aa>bb)?aa:bb;
+//        System.out.println(max);
+//
+//
+//        /**
+//         * 获取三个数中的最大值
+//         */
+//        int cc =1;
+//        int dd =2;
+//        int ee =3;
+//        cc = (cc>dd)?cc:dd;
+//        cc = (cc > ee)?cc:ee;
+//        System.out.println(cc);
+
+
+        /**
+         * 从键盘输入  1   1.0   "hello"   true
+         */
+//        Scanner scanner = new Scanner(System.in);
+//        //输入一个整型   1
+//        int nextInt = scanner.nextInt();
+//        System.out.println(nextInt);
+//        //nextDouble
+//        double nextDouble = scanner.nextDouble();
+//        System.out.println(nextDouble);
+//        //String
+//        String next = scanner.next();
+//        System.out.println(next);
+//        //boolean
+//        boolean bool = scanner.nextBoolean();
+//        System.out.println(bool);
+
+
+        /**
+         * **案例:**小明注册某交友网站,要求录入个人相关信息。如下:
+         *
+         * 请输入你的网名(String)、你的年龄(int)、你的体重(double)、你是否单身(an)、你的性别(int)等情况
+         */
+//        Scanner scanner = new Scanner(System.in);
+//        System.out.println("请输入你的网名");
+//        String name = scanner.next();
+//        System.out.println(name);
+//        System.out.println("你的年龄(int)");
+//        int age = scanner.nextInt();
+//        System.out.println(age);
+//        System.out.println("你的体重(double)");
+//        double nextDouble = scanner.nextDouble();
+//        System.out.println(nextDouble);
+//        System.out.println("你是否单身");
+//        String single = scanner.next();
+//        System.out.println(single);
+//        System.out.println("你的性别(int)");
+//        int sex = scanner.nextInt();
+//        System.out.println(sex);
+//        System.out.println("输入完成");
+
+        /**
+         * System.out.println(“是否中分: (1/0));
+         * scanner.nextInt();
+         *
+         * System.out.println(“篮球: (true/false));
+         * scanner.nextBoolean();
+         *
+         * System.out.println(“背带裤: (是/否));
+         * scanner.next();   //"是".equals(str)
+         */
+        Scanner scanner = new Scanner(System.in);
+        System.out.println("是否中分: (1/0)");
+        int nextInt = scanner.nextInt();
+        System.out.println("篮球: (true/false)");
+        boolean aBoolean = scanner.nextBoolean();
+        System.out.println("背带裤: (是/否)");
+        String next = scanner.next();
+        if(nextInt == 1 && aBoolean == true && next.equals("是")){
+            System.out.println("真爱粉");
+        }else if(nextInt == 1 || aBoolean == true || next.equals("是")){
+            System.out.println("假ikun");
+        }else {
+            System.out.println("小黑子");
+        }
+
+
+
+    }
+
+
+    public static void eat(String   str){
+        System.out.println(str);
+    }
+
+
+
+
+
+}

BIN
target/classes/com/sf/day01/Test01.class


BIN
target/classes/com/sf/day02/Test.class