栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java练习

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java练习

1.闰年判断

package test;
import java.util.Scanner;

public class Task02 {
public static void main(String[] args) {
// 声明部分
int year;
String result;
Scanner sc = new Scanner(System.in);

    // 输入部分
    System.out.print("year = ");
    year = sc.nextInt();

    // 处理部分
    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
        result = year + "是闰年。";
    } else {
        result = year + "是平年。";
    }
    // 输出部分
    System.out.println(result);
}

}

2.计算圆面积(选择结构版)

package test;
import java.util.Scanner;
public class Task02_1 {
public static void main(String[] args) {
double r, s;
final double PI = 3.14;
Scanner sc = new Scanner(System.in);

    System.out.print("r = ");
    r = sc.nextDouble();

    if (r < 0) {
        System.out.println("温馨提示,半径不能为负!");
        return;
    }
    s = PI * r * r;

    System.out.println("s = " + s);
}

}
3.成绩等级评定





package test;
import java.util.Scanner;
public class Task02_2 {
public static void main(String[] args) {
// 声明部分
int score;
String level;
Scanner sc = new Scanner(System.in);

    // 输入部分
    System.out.print("score = ");
    score = sc.nextInt();

    // 处理部分
    level = "";
    if (score > 100) level = "超出范围";
    if (score >= 90 && score <= 100) level = "优秀";
    if (score >= 80 && score < 90) level = "良好";
    if (score >= 70 && score < 80) level = "中等";
    if (score >= 60 && score < 70) level = "及格";
    if (score >= 0 && score < 60) level = "不及格";
    if (score < 0) level = "超出范围";

    // 输出部分
    System.out.println(level);
}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/891613.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号