从键盘上输入三科成绩,输出平均值以及和用Java写一个程序
时间: 2024-05-14 09:15:02 浏览: 11
```
import java.util.Scanner;
public class AverageScore {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入三科成绩:");
double score1 = input.nextDouble();
double score2 = input.nextDouble();
double score3 = input.nextDouble();
double average = (score1 + score2 + score3) / 3;
double sum = score1 + score2 + score3;
System.out.println("平均分:" + average);
System.out.println("总分:" + sum);
}
}
```
相关问题
用java写一个从键盘上输入三科成绩,成绩大于85分的判定为优秀
import java.util.Scanner;
public class GradeChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int score1, score2, score3;
System.out.print("请输入第一科成绩:");
score1 = scanner.nextInt();
System.out.print("请输入第二科成绩:");
score2 = scanner.nextInt();
System.out.print("请输入第三科成绩:");
score3 = scanner.nextInt();
if (score1 > 85) {
System.out.println("第一科成绩优秀!");
}
if (score2 > 85) {
System.out.println("第二科成绩优秀!");
}
if (score3 > 85) {
System.out.println("第三科成绩优秀!");
}
}
}
我想用结构体从键盘输入十个学生的学号,姓名,三科学科成绩,然后输出他们三科成绩的平均值和成绩最高的学生的所有信息
可以的,以下是代码示例:
#include <stdio.h>
#define NUM 10 // 学生数量
struct Student {
int id; // 学号
char name[20]; // 姓名
float score[3]; // 三科成绩
};
int main() {
struct Student stu[NUM];
float avg[3] = {}; // 三科成绩平均值
int max_index = ; // 成绩最高的学生下标
// 输入学生信息
for (int i = ; i < NUM; i++) {
printf("请输入第%d个学生的学号、姓名、三科成绩:\n", i+1);
scanf("%d %s %f %f %f", &stu[i].id, stu[i].name, &stu[i].score[], &stu[i].score[1], &stu[i].score[2]);
// 计算平均值
avg[] += stu[i].score[];
avg[1] += stu[i].score[1];
avg[2] += stu[i].score[2];
// 找出成绩最高的学生
if (stu[i].score[] + stu[i].score[1] + stu[i].score[2] > stu[max_index].score[] + stu[max_index].score[1] + stu[max_index].score[2]) {
max_index = i;
}
}
// 输出平均值和成绩最高的学生信息
printf("三科成绩平均值为:%.2f %.2f %.2f\n", avg[]/NUM, avg[1]/NUM, avg[2]/NUM);
printf("成绩最高的学生信息为:\n");
printf("学号:%d\n", stu[max_index].id);
printf("姓名:%s\n", stu[max_index].name);
printf("三科成绩:%.2f %.2f %.2f\n", stu[max_index].score[], stu[max_index].score[1], stu[max_index].score[2]);
return ;
}
相关推荐
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)