• 0705作业


    1:常见的算术运算符有哪些?
    +运算符的作用有哪些?
    除法和取余的区别?
    ++和--的使用规则?

    2:常见的赋值运算符有哪些?
    +=运算的作用是什么?
    扩展的赋值运算符有什么特点?

    3:short s = 1; s = s + 1;有没有问题?如果有怎么解决?
    short s = 1; s += 1;有没有问题?如果有怎么解决?

    4:常见的关系运算符有哪些?
    关系运算符的结果有什么特点?

    5:常见的逻辑运算符有哪些?
    &和&&的区别是什么?
    |和||的区别是什么?

    6:位运算符^的特点是什么?

    7:如何实现对两个整数变量的值进行互换。

       使用第三方变量。

    int a=1;

    int 2=12;

    int temp=a;
    a=b;
    b=temp;

    8:三元运算符的格式是什么?
    执行流程是什么?

    关系表达式?表达式1:表达式2;



    9:使用三元运算符完成如下练习
    比较两个数是否相等
    获取两个数中最大值
    获取三个数中最大值

    int a = 10;

    int b = 20;

    boolean b1 = (a == b);

     

    int a = 10;

    int b = 10;

    int max = (x > y) ? x : y;

     

    int a = 10;

    int b = 20;

    int c = 30;

    int temp = (x > y)? x : y;

    int max = (temp > z)? temp : z;



    10:流程控制语句有几种?

    顺序结构
    选择结构 if switch
    循环结构 for while do...while

     

    11:if语句的格式有几种?注意事项是什么?分别在什么时候使用?

    if语句的格式有3.

    一般来说:有左大括号就没有分号,有分号就没有左大括号

    else后面是没有比较表达式的,只有if后面有。

    最后一个else可以省略,但是建议不要省略,可以对范围外的错误值提示

    12:看程序写结果:请自己独立分析,先不要编译运行。
    第一题
    int x = 1,y = 1;

    if(x++==2 & ++y==2)//两边都执行
    {
    x =7;
    }
    System.out.println("x="+x+",y="+y);

    x=2  y=2

    ---------------------------------------------------
    第二题
    int x = 1,y = 1;

    if(x++==2 && ++y==2)//左边执行,右边不执行
    {
    x =7;
    }
    System.out.println("x="+x+",y="+y);

    x=2  y=1

    ---------------------------------------------------
    第三题
    int x = 1,y = 1;

    if(x++==1 | ++y==1)
    {
    x =7;
    }
    System.out.println("x="+x+",y="+y);

    x=7  y=2

    ---------------------------------------------------
    第四题
    int x = 1,y = 1;

    if(x++==1 || ++y==1)
    {
    x =7;
    }
    System.out.println("x="+x+",y="+y);

    x=7  y=2

    ---------------------------------------------------
    第五题
    boolean b = true;

    if(b==false) 
    System.out.println("a");
    else if(b)
    System.out.println("b");
    else if(!b)
    System.out.println("c");
    else
    System.out.println("d");

    flase

    ---------------------------------------------------

    13:编写代码实现如下内容:if语句实现
    考试成绩分等级。
    90~100 A等。
    80-89 B等。
    70-79 C等。
    60-69 D等。
    60以下 E等。
    请根据给定成绩,输出对应的等级。

    import java.util.Scanner;

    public class Test1_IF1 {

    public static void main(String[] args) {

    Scanner sc=new Scanner(System.in);

    System.out.println("请输入成绩:");

    int score=sc.nextInt();

    if (score>=90 && score<=100) {

    System.out.println("A等");

    }else if (score>=80 && score<=89) {

    System.out.println("B等");

    }else if (score>=70 && score<=79) {

    System.out.println("C等");

    }else if (score>=60 && score<=69) {

    System.out.println("D等");

    }else if (score>=0 && score<60)   {

    System.out.println("E等");

    }else {

    System.out.println("您输入的成绩有误,请重新输入");

    }

    }

    }

    14:switch语句的格式?针对格式的解释?以及注意事项?

    switch(表达式) {
           case 值1:
           语句体1;
           break;
           case 值2:
           语句体2;
           break;
           …
           default:    
           语句体n+1;
           break;
            }

    case后面只能是常量,不能是变量,而且,多个case后面的值不能出现相同的

    15:看程序,分析下面程序的结果:
    int x = 2,y=3;

    switch(x)
    {
    default:
    y++;
    case 3:
    y++;
    break;
    case 4:
    y++;
    }

    System.out.println("y="+y);

    y=4

    16:根据输入的值,判断是星期几。(分别用if语句和switch语句实现)
    输入:
    输出:星期

    import java.util.Scanner;

    public class Text4_IF {

    public static void main(String[] args) {

    Scanner sc=new Scanner(System.in);

    System.out.print("输入:");

    int week=sc.nextInt();

    //输入:1 输出:星期1

    if (week==1) {

    System.out.println("星期1");

    }else if (week==2) {

    System.out.println("星期2");

    }else if (week==3) {

    System.out.println("星期3");

    }else if (week==4) {

    System.out.println("星期4");

    }else if (week==5) {

    System.out.println("星期5");

    }else if (week==6) {

    System.out.println("星期6");

    }else if (week==7) {

    System.out.println("星期日");

    }else {

    System.out.println("输入的日期有误!");

    }

    }

    }

     

    import java.util.Scanner;

    public class Text3_Switch {

    public static void main(String[] args) {

    Scanner sc=new Scanner(System.in);

    System.out.print("输入:");

    int week=sc.nextInt();

     

    switch (week) {

    case 1:

    System.out.println("星期1");

    break;

    case 2:

    System.out.println("星期2");

    break;

    case 3:

    System.out.println("星期3");

    break;

    case 4:

    System.out.println("星期4");

    break;

    case 5:

    System.out.println("星期5");

    break;

    case 6:

    System.out.println("星期6");

    break;

    case 7:

    System.out.println("星期日");

    break;

    default :

    System.out.println("对不起,您输入有误");

    break;

    }

    }

    }

    17:把今天讲过的其他案例再练习一遍

  • 相关阅读:
    大话设计模式笔记 观察者模式
    nginx限速
    枚举实现的单例模式
    Nginx负载均衡
    插件lombok的介绍安装
    ThreadLocal类
    CopyOnWriteArrayList并发容器
    ConcurrentHashMap实现原理
    elasticsearch配置文件
    sql优化
  • 原文地址:https://www.cnblogs.com/wty1994/p/9270199.html
Copyright © 2020-2023  润新知