Java三大结构

字符串: string(不是基础数据类型,应用数据类),字符串必须使用“  ”+ : 链接字符串,如果其他的数据类型+“  ”就变成了字符串

if:if多用于范围选择,switch多个单值匹配。java中的switch可以是整数、字符(java中char会自动转换了int)

if(2>1){
			System.out.println("成立");
		}else{
			System.out.println("不成立");
		}

switch:

	int score = 'a';

		switch(score){
			case 'a':System.out.println("优秀");break;
			case 'b':System.out.println("良好");break;
			case 'c':System.out.println("及格");break;
			case 'd':System.out.println("差生");break;
			default:System.out.println("不清楚");

		}

循环

while:

int i = 0;
		while(i<100){
			System.out.println("i:"+i);
			i++;

do while

int j = 0;

		do{
			System.out.println("j:"+j);
			j++;
		}while(j<100);

while 和 do while的区别是,dowhile至少会执行一次

while和if的区别:结束的地方不一样,while条件结束,当满足条件执行完了后还需要进行一次条件判断就while

int a = 1;
	int b = 2;
	if(a<b){
		System.out.println("a<b");
		a=3;
	}
	int c = 1;
	int d = 2;
	while(c<d){
		System.out.println("c<d");
		c=3;
		
	}

break 和 continue

for(){
		for(int h=0;h<10;h++){
			if(h==5){
				//跳出本次循环
				continue;
				//break;//跳出本层循环
			}
			System.out.println(h);
	}
	}

		for(;;){//是死循环
			System.out.println("1111111");
		}	
	}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值