zoukankan      html  css  js  c++  java
  • 笔记3

    public class jh_01_为什么需要if选择结构 {
     /*
      * 如果张浩的Java考试成绩大于98分,
      * 张浩就能获得一个苹果 。作为奖励
      */
     public static void main(String[] args) {
      
      // 指令。
      // 1:注释起来,2:删除指令。
      System.out.println("获得一个苹果");
      // 条件:张浩的Java考试成绩大于98分
    //  javaScore > 98
      // 用表达式表示咱们的条件。
      System.out.println("I love you");
      
      System.out.println("I love you");
      System.out.println("I love you");
      System.out.println("I love you");
     }
    }
    public class jh_02_代码块的概念 {
     
     // {} 用大括号括起来的内容就叫代码块。
     public static void main(String[] args) {
      int a = 10;
      
      {
       System.out.println(a);
      }
      
      {
       System.out.println("获得奖励");
      }
      
      {
      
       System.out.println("I love you ");
      }
     }
    }
     
     
    public class jh_03_什么是if选择结构 {
     /*
      *  如果张浩的Java考试成绩大于98分,
      * 张浩就能获得一个苹果 。作为奖励
      */
     public static void main(String[] args) {
      //Java考试成绩大于98分
    //  javaScore > 98
      int javaScore = 99;
      
      if(javaScore < 98){
       System.out.println("获得一个苹果");
      }
      
      System.out.println("你好。");
     }
    }
     public class jh_04_if选择结构练习 {
     public static void main(String[] args) {
      int a = 99;
      int b = 98;
      
      boolean result = a > 98 && b>80 || a == 100 && b>70;
      if(result) {
       System.out.println("jl");
      }
     }
    }
    import java.util.Scanner;
    public class jh_06_学员操作_实现幸运抽奖2_1 {
     /*
      * 需求说明
      * int random = (int)(Math.random()*10);
      * 抽奖规则:
      * 会员号的百位数字
      * 等于产生的随机数字
      * 即为幸运会员
      * condition
      */
     public static void main(String[] args) {
      
    //  System.out.println(random);
      Scanner sc = new Scanner(System.in);
      System.out.println("请输入卡号:");
      int cardNo = sc.nextInt();
      // 根据卡号求出百位数值。
      int baiwei = cardNo / 100 % 10;
      int random = (int)(Math.random()*10);
      
      
      if (random == baiwei) {
       System.out.println("中奖了。");
      } else {
       System.out.println("谢谢惠顾。");
      }
     }
    }
    import java.util.Scanner;
    public class jh_08_random玩一局剪刀石头布 {
     public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      //给出出拳。1:剪刀2:石头 3:布
      System.out.println("请输入你出的拳:1:剪刀2:石头 3:布");
      int a = sc.nextInt();
      int b = (int)(Math.random()*3)+1;
    //  System.out.println(b);
      // 判断。
      if(a == b) {
       //平局
       System.out.println("平局。");
      }else {
       // 不是平局。
       if((a == 1 && b == 3) || (a == 2 && b == 1)||(a == 3 && b == 2)) {//
        System.out.println("你赢了。");
       }else {
        System.out.println("你输了");
       }
      }
    public class jh_09_为什么使用多重if选择结构 {
     /*
      * score = ?;
      * 区间----
      * [0,60)----- score >= 0 && score < 60
      *
      * [60,80)
      * [80,100]
      * 对学员的结业考试成绩评测
      成绩>=80 :良好
      成绩>=60 :中等
      成绩<60   :差
      */
     public static void main(String[] args) {
      int score = 75;
      if (score >= 0 && score<60) {
       System.out.println("不及格");
      }else if (score>=60&&score<80) {
       System.out.println("及格");
      }else if (score>=80&&score<100) {
       System.out.println("优秀");
      }else if (score == 100){
       System.out.println("满分");
      }else {
       System.out.println("成绩有误。");
      }
      
      // 输入月份。判断对应属于哪个季节。
      // 春季,夏季,秋季,冬季。
    //  春季   month : 3,4,5  month == 3 || month == 4 || month == 5
      
      
      
      
      
      
      
    //  int score = 55;
    //  //成绩<60   :差
    //  if(score >= 0 && score < 60) {
    //   System.out.println("差");
    //  }
    //  
    //  if(score >= 60 && score < 80) {
    //   System.out.println("中等");
    //  }
    //  
    //  if(score >= 80 && score < 100) {
    //   System.out.println("优秀");
    //  }
    //  
    //  if(score == 100) {
    //   System.out.println("满分");
    //  }
     }
    }
     public class jh_10_str的equals {
     public static void main(String[] args) {
    //  String str = "男";
    //  str = null;
      //NullPointerException
    //  if(str.equals("男")) {
    //   
    //  }
    //  if ("男".equals(str)) {
    //   
    //  } else {
    //
    //  }
      
      //String str = "男";
      
      if() {
       // 根据性别
       if() {
        
       }else {
        
       }
       
      }else {
       
      }

     }
    }
     
     
     
     
     
     
     
     
     
  • 相关阅读:
    SDK Hello world(直接使用SDK封装)
    一个类有多个基类的内存布局
    写个测试程序看看磁盘映像文件中哪个扇区可以使用?
    在服务中以当前用户身份启动一个程序
    在类有成员变量的场景下, 按照虚表原理, 模拟虚函数实现
    pipe----管道
    Qt序列化格式分析(qint,QString)(非常简单好用)
    模拟QQ系统设置面板实现功能
    Qt持久性对象进行序列化(同时比较了MFC与Java的方法)
    使用srvany.exe将任何程序作为Windows服务运行
  • 原文地址:https://www.cnblogs.com/mkop/p/11382833.html
Copyright © 2011-2022 走看看