今天是我来黑马的第三天,我只想用代码来说我干了什么package com.itheima_1;
import java.util.Scanner;
public class DayThreeHomeWork {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
// 输入分数
System.out.print("请输入分数:");
float score = sc.nextFloat();
// 判断学生的成绩等级
if (score < 0 || score > 100) {
System.out.println("成绩输入错误!请重新输入!");
} else if (score < 60) {
System.out.println("成绩不合格!");
} else if (score < 70) {
System.out.println("成绩及格!");
} else if (score < 80) {
System.out.println("成绩良!");
} else if (score < 90) {
System.out.println("成绩好!");
} else {
System.out.println("成绩优秀!");
}
System.out.println("--------------------");
// 求1-100之间的奇数和
int sum1 = 0;
int sum2 = 0;
int sum3 = 0;
for (int i = 1; i <= 100; i++) {
if (i % 2 == 1) {
sum1 += i;
} else {
sum2 += i;
}
}
for (int i = 1; i <= 100; i++) {
if ((i % 3 == 0) && (i % 5 == 0)) {
sum3 += i;
}
}
// 输出结果
System.out.println("1-100之间的奇数和为sum1=" + sum1);
System.out.println("1-100之间的偶数和为sum2=" + sum2);
System.out.println("1-100之间既是3又是5的倍数的数和为sum3=" + sum3);
System.out.println("--------------------");
//求一个三位数的各数位满足条件的数的和
System.out.print("请输入一个三位数:");
int a = sc.nextInt();
int sum0 = 0;
for (int i = 100; i <= a; i++) {
if(a < 100 || a > 999) {
System.out.println("输入有误!");
break;
} else {
int w1 = i % 10;
int w2 = (i / 10) % 10;
int w3 = i / 100;
if (w1 != 7 && w2 != 5 && w3 != 3) {
sum0 += i;
}
}
}
if (a >= 100 && a <= 999){
System.out.println("满足条件的三位数的和为sum0:" + sum0);
}
System.out.println("--------------------");
// switch语句的循环
while (true) {
System.out.print("请输入一个1-5的整数:");
int num = sc.nextInt();
switch (num) {
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("退出");
System.exit(0);
break;
default:
System.out.println("输入有误!");
break;
}
}
}
}
|
|