学Java的四天(在入土的边缘疯狂试探。。。)

嘛,今天终于出太阳了,感觉人生又有了希望,而今天学的是判断之类的东西,还好我在这种方面很少栽跟头,就好像我的人生前途光明???

今天的内容如下:

/**
    字符串:String(不是基础数据类型,引用数据类)字符串必须使用""
    +:链接字符串,如果其他的数据类型+""就变成了字符串
    三目,

    ++a;a+b,

*/
class JavaDemo6 
{
    public static void main(String[] args) 
    {
        String name  = "haoren";
        String name1 = new String("huairen");
        int temp = 3;
        System.out.println(name);
        System.out.println(name1);
        System.out.println(temp+""+1);

        int score = 65;
        System.out.println(score>=80?"优秀":"及格");//条件表达式(三目运算)
    }
}
 

**
    三大结构:
        顺序
        选择:
            if  else switch

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

*/

class JavaDemo7 
{
    public static void main(String[] args) 
    {
        //选择
        if(2>1){
            System.out.println("成立");
        }else{
            System.out.println("不成立");
        }
        /*
        if(){
            if(){

            }
        }

        if(){

        }else if(){

        }
        */

        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("不清楚");

        }
        

    //循环:
    /*
        int i = 0;
        while(i<100){
            System.out.println("i:"+i);
            i++;
        }

        int j = 0;

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

        for(int k=0;k<100;k++){
            System.out.println("k:"+k);
        }
*/

//while 和 do while的区别是,dowhile至少会执行一次
//边界值问:只要限定范围就需要注意边界值

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

        int j = 0;

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

        System.out.println(j);


        //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;
        
    }
    
    }

    
}
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值