zoukankan      html  css  js  c++  java
  • 第四次作业 java程序设计国庆作业

    public class X{
      public static void main(String[] args){
        //第一题
        System.out.println("5+5="+5+5);
        //第二题
        int a=3,b;
        b=a++;
        System.out.println("a="+a+",b="+b);
        //第三题
        short s=3;
        s=(short)(s+4);//不兼容的类型: 从int转换到short可能会有损失.+short
        System.out.println("s="+s);
        //第四题位运算符
        System.out.println(6&3);//无条件与
        System.out.println(6|3);//无条件或
        System.out.println(3^3);//当不一样的时候为真 1和0为真 一样的时候为假 0和0 1和1
        System.out.println(3<<2);//左移 实际上是用来计算3*2^2=12
        System.out.println(3>>1);//右移 实际上是用来计算除法 3/(2^1)=1//sop(3>>>1)也是右移,不同之处在于出现的空位都用0补
        //第五题三元运算符
        int x=3,y;
        y=x>1?100:200;//三元条件,判断x是否大于1,若是y=100,若不是y=200,右结合性
        System.out.println("y="+y);
        //用三元运算符做联系
        int z=15,q=10,v=8,e;
        System.out.println(e=z>q?z:q);//输出两个整数中较大的整数
        System.out.println(e=z>q?z:q>v?q:v);//输出三个整数中最大的整数
        //第六题判断语句
        int weekDay=3;//判断星期
        if(weekDay==1){
          System.out.println("今天是星期一");
        }
        else if(weekDay==2){
          System.out.println("今天是星期二");
        }
        else if(weekDay==3){
          System.out.println("今天是星期三");
        }
        else if(weekDay==4){
          System.out.println("今天是星期四");
        }
        else if(weekDay==5){
          System.out.println("今天是星期五");
        }
        else if(weekDay==6){
          System.out.println("今天是星期六");
        }
        else if(weekDay==7){
          System.out.println("今天是星期日");
        }
        else{
          System.out.println("没有这一天");
        }
        int month=8;//判断季节
        if(month==3||month==4||month==5){
          System.out.println("现在是春天");
        }
        else if(month==6||month==7||month==8){
          System.out.println("现在是夏天");
        }
        else if(month==9||month==10||month==11){
          System.out.println("现在是秋天");
        }
        else if(month==12||month==1||month==2){
          System.out.println("现在是冬天");
        }
        else{
          System.out.println("没有这个季节");
        }
        //第七题使用分支语句
        int c=84,h=3;
        char option='+';
        switch (option)
        {
        case '+':
          System.out.println("c+h="+(c+h));
          break;
        case '-':
          System.out.println("c-h="+(c-h));
          break;
        case '*':
          System.out.println("c*h="+(c*b));
          break;
        case '/':
          System.out.println("c/h="+(c/h));
          break;
        case '%':
          System.out.println("c%h="+(c%h));
          break;
        default:
          System.out.println("c%h="+(c%h));
          break;
        }
        //使用switch判断季节
        int mon=8;
        switch(mon)
        {
        case 3:
        case 4:
        case 5:
          System.out.println("现在是春天");
          break;
        case 6:
        case 7:
        case 8:
          System.out.println("现在是夏天");
          break;
        case 9:
        case 10:
        case 11:
          System.out.println("现在是秋天");
          break;
        case 12:
        case 1:
        case 2:
          System.out.println("现在是冬天");
          break;
        default:
          System.out.println("没有这个季节");
          break;
        }
        //第八题do while和while的区别
        int d=1;
        do{
          System.out.println("d="+d);
          d++;
        }while(d<1);//不管while里面的条件是否成立,do里面的都要运行
        int f=1;
        while(f<1){
          System.out.println("f="+f);
          f++;
        }
        //第九题使用for语句写一个简单的循环语句
        for(int g=1;g<5;g++)
        {
          System.out.println("g="+g);
        }
      }
    }

  • 相关阅读:
    ajax方式下载文件
    chrome常用插件
    c3p0配置之preferredTestQuery参数默认值探秘
    细说tomcat之集群session共享方案
    细说tomcat之session持久化探秘
    细说tomcat之类加载器
    细说tomcat之应用监控
    细说RESTful API之设计原则
    细说RESTful API安全之防止重放攻击
    细说RESTful API安全之防止数据篡改
  • 原文地址:https://www.cnblogs.com/xyayy/p/7617098.html
Copyright © 2011-2022 走看看