public class 实验一1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int mark;
int[] number = new int[5];
char[] grade = { 'A', 'B', 'C', 'D', 'E' };
while (true) {
System.out.println("Please input a mark:");
mark = Int();
if (mark < 0) {
break;
}
switch (mark / 10) {
case 9:
number[0]++;
break;
case 8:
number[1]++;
break;
case 7:
number[2]++;
break;
case 6:
number[3]++;
break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:
number[4]++;
break;
case 10:
if (mark % 100 == 0) {
number[0]++;
break;
}
default:
System.out.println("Error input!");
break;
}
}
for (int i = 0; i < grade.length; i++) {
System.out.print("The number of " + grade[i] + " grade:");
System.out.println(number[i]);
}
}
}
public class 实验一2 {
public static void main(String[] args) {
int i,m=1,sum=0;
for(i=1;sum<9000;i++){
m=m*i;
sum=sum+m;
}
i=i-2;
System.out.println("n="+i);
}
}
import java.util.Scanner;
public class 实验一3 {
public static void main(String[] args) {
Scanner Num = new Scanner(System.in);
System.out.println("最大行数15");
System.out.print("输入行数:");
int num = Int();
if (num > 15) {
System.out.println("输入错误");
} else {
打印 triangle = new 打印();
triangle.Triangle(num);
}
}
private void Triangle(int num) {
int i, j;
for (int Num = num; Num > 0; Num--) {
if (Num >= 10) {
for (j = num - Num; j > 0; j--) { // 输出空格
System.out.print(" ");
}
} else {
for (j = num - Num; j > 0; j--) { // 输出空格
System.out.print(" ");
}
for (int k = num - 9; k > 0; k--) {
System.out.print(" ");
}
}
for (i = -Num; i <= Num; i++) { // 输出数字
if (i == 0 || i == 1)
continue;
System.out.print("" + Math.abs(i) + " ");
}
System.out.println();
}
}
}
import java.util.Scanner;
public class 实验一4 {
public static void main(String[] args) {
int[][] score = new int[8][3];
int[] all = new int[8];
Scanner in = new Scanner(System.in);
System.out.println("输入学生成绩");
int i, j;// i表示学生人数,j表示课程数
for (i = 0; i < 8; i++) {
for (j = 0; j < 3; j++) {
System.out.println("请输入第" + (i + 1) + "个学生的第" + (j + 1)
+ "个课程的分数");
score[i][j] = in.nextInt();
all[i] = all[i] + score[i][j];
}
}
for (j = 0; j < 3; j++) {// 求平均分
int sum = 0;
字符串函数源码for (i = 0; i < 8; i++) {
sum = sum + score[i][j];
}
System.out.println("第" + (j + 1) + "门课的平均成绩是:" + (double) sum / 8);
}
int max = all[0];
int n = 0;
for (j = 0; j < 8; j++) {
if (max <= all[j]) {
max = all[j];
n = j;
}
}
System.out.println("总分最高的是第" + (n + 1) + "个同学,总成绩为:" + max);
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论