Java习题


一、需求:
1.用if语句判断一个数字的奇数偶数?

提示:
1.通过取余数的方法判断

public class Test
{
    public static void main(String[] args){
        int i = 20;
        if(i%2 == 0){
            System.out.println(i+" "+"偶数");
        }else{
            System.out.println("奇数");
        }
    }
}




二、需求:
输入为90

输出一个学生的成绩等级
分数大于80--优秀
分数大于70--良好
分数大于60--合格
分数为其他--不合格

 

public class Test
{
    public static void main(String[] args){
        int i = 80;
        if(i>80){
            System.out.println("优秀");
        }else if(i>70){
            System.out.println("良好");
        }else if(i>60){
            System.out.println("合格");
        }else if(i<=60){
            System.out.println("不合格");
        }
    }
}


三、EX3
需求:
根据所给的数量值,来输出对应中文格式的星期
数字1~7 对应 一周七天
 

public class Test
{
    public static void main(String[] args){
        int week = 8;
        switch(week){
            case 8:
            case 1:
                System.out.println("星期一");
                break;
            case 2:
                System.out.println("星期二");
                break;
            case 3:
                System.out.println("星期三");
                break;
            case 4:
                System.out.println("星期四");
                break;
            case 5:
                System.out.println("星期五");
                break;
            case 6:
                System.out.println("星期六");
                break;
            default:
                System.out.println("星期日");
                break;
        }
    }
}



四、EX4
需求:
用while循环,输出数字0~9

 

public class Test
{
    public static void main(String[] args){
        int i = 0;
        while(i<10){
            System.out.print(i);
            i+=1;
        }
    }
}


五、EX5
需求:
用for循环,输出数字0~9

public class Test
{
    public static void main(String[] args){
        //int i = 0;
        for(int i = 0; i<10; i++){
            System.out.print(i);
        }
    }
}




六、EX6
需求:
打印出一个如下三角形

*
**
***
****
*****
******
*******
********
*********

i 1   2   3  
j 1 1 2 1 2 3

*
**
***
..
直到第九行结束

public class Test
{
    public static void main(String[] args){
        int i,j;
        for(i = 1; i<=9; i++){

            for (j = 1; j<=i; j++)
            {
                System.out.print("*");
            }
            System.out.println("\n");
        }
    }
}



六、EX6
需求:
求取0~100之内的奇数和
*/

public class Test
{
    public static void main(String[] args){
        int i;
        int sum = 0;
        for (i = 1; i<=100; i++)
        {
            if (i%2==0)
            {
                continue;
            }
            sum+=i;
        }
        System.out.println(sum);
    }
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值