• 作业 金嘉琪 10 01


    1.输出的结果是什么?

    import java.util.Scanner;
    public class Prs
      {
        public static void main(String[] args)
          {
            System.out.println("5+5="+5+5);
          }
      }

    2.算出输出的结果(自增自减)

    public class Increase
      {
        public static void main(String[] args)
        {
          int a=3,b;
          b=a++;
          System.out.println("a="+a+",b="+b);

        }

      }

     

    3.算出结果

    public class Shortp
      {
        ublic static void main(String[] args)
        {
          short s=3;
          s+=4;
          System.out.println("s="+s);
        }

      }

    4.算出结果

    public class LogicalRelationship
      {
        public static void main(String[] args)
        {
          System.out.println(6&3);
          System.out.println(6|3);
          System.out.println(6^3);
          System.out.println(3<<2);
          System.out.println(3>>1);
        }

      }

     

    5.算出结果

    import java.util.Scanner;
    public class K {
       public static void main(String[] args) {
       int x=0,y;
       y=x>1?100:200;
       sop("y="+y);
       }
    }

    然后算出较大的数字

    public class Z
    {
    public static void main (String[] args){
    int a=1,b=0,max;
    max=a>b?a:b;
    System.out.println("max="+a);
    }

    }

     

    最后输出最大的数字

    public class Q
    {
      public static void main (String[] args){
      int a=1,b=0,c=3,max;
      max=a>b?a:b;
      max=c>max?c:max;
      System.out.println("max="+c);
     }

    }

     

    6.使用判断语句,根据数字,输出对应的中文是星期几

    import java.util.Scanner;
    public class WeekP
      {
        public static void main(String[] args)
          {
            Scanner input=new Scanner(System.in);
            System.out.print("请输入一个1-7之间的数: ");
            int weekday=input.nextInt();
            if(weekday==1)
            System.out.println("周一");
            if(weekday==2)
            System.out.println("周二");
            if(weekday==3)
            System.out.println("周三");
            if(weekday==4)
            System.out.println("周四");
            if(weekday==5)
            System.out.println("周五");
            if(weekday==6)
            System.out.println("周六");
            if(weekday==7)
            System.out.println("周日");
          }
    }

     

    7


    用判断语句,根据数字,输出对应季节

    import java.util.Scanner;
    public class SwitchP
      {
        public static void main(String[] args)
      {
        Scanner input=new Scanner(System.in);
        System.out.print("输入一个月份:");
        int a=input.nextInt();
        if(a>=3&&a<=5)
        System.out.println("春");
        if(a>=6&&a<=8)
        System.out.println("夏");
        if(a>=9&&a<=11)
        System.out.println("秋");
        if(a>=12&&a<=2)
        System.out.println("冬");cls
      }
    }

     

    8. 
    使用循环语句,分析程序的结果

    public class Dp
    {
      public static void main(String[] args)
      {
        int x=1;
        do
        {
          System.out.println("x="+x);
          x++;
        }

        while(x<1);
      }
    }

  • 相关阅读:
    linux -- 部署java服务器(3) linux安装redis
    linux 安装php8
    linux mysql查看日志
    linux mysql常用的命令
    perl heredoc
    perl数值进制
    提问的智慧
    How to ask question the smart way
    PERL命令行
    图灵/异步图书
  • 原文地址:https://www.cnblogs.com/ninomiya617/p/7670705.html
Copyright © 2020-2023  润新知