第六天 继续(今天收到一个IT岗面试的测试题,很有意思,是关于课程设计的,没有JAVA的内容,但我想先做做试试,如果进面试的看条件怎么样,如果理想,我想试着干一干,但也担心影响找开发岗但近期我找不到)

顺序结构

任何算法都无法离开的基础结构

package Xuexi.struct;
​
public class ShenXuDemo {
    public static void main(String[] args) {
        System.out.println("hello1");
        System.out.println("hello2");
        System.out.println("hello3");
        System.out.println("hello4");
    }
}

选择结构

if

if单选择结构

package Xuexi.struct;
​
import java.util.Scanner;
​
public class IfDemo01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
​
        System.out.println("请输入内容:");
        String s = scanner.nextLine();
​
        //equals:判断字符串是否相等
        if (s.equals("Hello")){
            System.out.println(s);
        }
        System.out.println("End");
        scanner.close();
​
    }
}

if双选择结构

package Xuexi.struct;
​
import java.util.Scanner;
​
public class IfDemo02 {
    public static void main(String[] args) {
        //考试分数大于60为及格,小于六十不及格
        Scanner scanner = new Scanner(System.in);
​
        System.out.println("请输入成绩:");
        int i = scanner.nextInt();
​
        if (i>60) {
            System.out.println("及格");
        }else{
            System.out.println("不及格");
        }
​
        scanner.close();
    }
}

if多选择结构

package Xuexi.struct;
​
import java.util.Scanner;
​
public class IfDemo03 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
​
        System.out.println("输入成绩:");
        int i = scanner.nextInt();
​
        if (i == 100) {
            System.out.println("满分");
        } else if (i < 100 && i > 90) {
            System.out.println("A");
        } else if (i < 90 && i > 70) {
            System.out.println("B");
        } else if (i < 70) {
            System.out.println("D");
        } else {
            System.out.println("骗人");
​
        }
        scanner.close();
    }
​
}

if嵌套结构

switch

switch多选择结构

从java se7 开始

package Xuexi.struct;
​
public class SwitchDemo01 {
    public static void main(String[] args) {
        //case穿透  //switch匹配一个具体的值
        char grade = 'A';
​
        switch (grade){
            case 'A':
                System.out.println("优秀");
                break;//可选
            case 'B':
                System.out.println("良好");
                break;//可选
            case'C':
                System.out.println("不错");
                break;//可选
            default:
                System.out.println("未知");
        }
    }
​
}

package Xuexi.struct;
​
public class SwitchDemo02 {
    public static void main(String[] args) {
        String name = "王东";
        //jdk7新特性,支持输出字符串
        //字符的本质还是数字
​
        //反编译 java----class(字节码文件)---反编译(IDEA)
        switch (name){
            case "王懂":
                System.out.println("王懂");
                break;
            case "王东":
                System.out.println("王东");
                break;
            default:
                System.out.println("王1");
​
        }
    }
}

循环结构

while循环

  • 只要布尔表达式为true就会一直执行

    package Xuexi.struct;
    ​
    public class WhileDemo01 {
        public static void main(String[] args) {
            //输出1-100
            int i =0;
            while (i<100){
                i++;
                System.out.println(i);
            }
        }
    }
    ​
package Xuexi.struct;
​
public class WhileDemo02 {
    public static void main(String[] args) {
        //计算1+2+3+。。。+100=?
        int i =0;
        int sum = 0;
        while(i<=100){
            sum = sum+i;
            i++;
    }
        System.out.println(sum);
​
    }
}

do...while循环

  • 至少会执行一次

  • while先判断后执行,dowhile先执行后判断

package Xuexi.struct;
​
public class DoWhileDemo01 {
    public static void main(String[] args) {
        int i = 0;
        int sum = 0;
​
        do {
            sum = sum +i;
            i++;
        }while (i<=100);
        System.out.println(sum);
    }
}
package Xuexi.struct;
​
public class DoWhileDemo02 {
    public static void main(String[] args) {
        int a = 0;
        while (a<0){
            System.out.println(a);
            a++;
        }
        System.out.println("===============");
        do {
            System.out.println(a++);
        }while (a<0);
    }
}
​
  • 31
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值