Java字符串+三大结构:顺序,选择,循环

字符串: string(不是基础数据类型,应用数据类),字符串必须使用“  ”

+ : 链接字符串,如果其他的数据类型+“  ”就变成了字符串

public static void main(String[] args) 
	{
		String name ="何宛橙";
		String nam= new String ("袁新鑫");
		int temp = 5 ;
		System.out.println(name);
		System.out.println(nam);
		System.out.println(temp+"520"+1);
       System.out.println(nam+temp+""+1+name);
		
	}

三目运算(a?b:c)

	public static void main(String[] args) 
	{
       int a=80;
	   System.out.println(a>=80?"优秀":"及格");
		
	}

 

三大结构:

if许多用于范围,switch多个单值匹配,java中的switch可以是字符,可以是字符串,java中char型会自动转化为int型

选择:

if    else     switch

if

int a= 60;
		if(a>=60){
		System.out.println("合格");
		}else if(a<60){
			System.out.println("不合格");
		}

switch

int b=4;
		switch (b)
		{
		case 10 : System.out.println("优秀");
		break;
		case 9 :  System.out.println("非常好");
		break;
		case 6 : System.out.println("及格");
		break;
		case 5 : System.out.println("不及格");
		break;
        default : System.out.println("劝退");
		
		}

循环

while 和 do while的区别  do while至少会执行一次; 

边界值问题:只要限定范围就需要注意边界值

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

while     do   while   for

while 

int c=0;
		while(c<10){
		System.out.println("c"+c);
		c++;
		}

do  while

int d=0;
		do
		{
			System.out.println("d"+d);
			d++;

		}
		while (d<10);

for 

	 for ( int t=0;t<10 ;t++ )
	 {
		 System.out.println("t"+t);
	 }

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值