编写一个 Java 程序来查找学生成绩并附带示例。为此,我们首先需要计算给定科目的总分和百分比。
Java 程序查找学生成绩示例
此 程序 帮助用户输入五门科目的五个不同的整数值。接下来,它会计算这五门科目的总分和百分比。
为此,我们使用 Java 算术运算符 来执行算术运算。接下来,我们使用 Java Else If 语句 来显示成绩。
import java.util.Scanner;
public class StudentGrade {
private static Scanner sc;
public static void main(String[] args)
{
int english, chemistry, computers, physics, maths;
float total, Percentage;
sc = new Scanner(System.in);
System.out.print(" Please Enter the Five Subjects Marks : ");
english = sc.nextInt();
chemistry = sc.nextInt();
computers = sc.nextInt();
physics = sc.nextInt();
maths = sc.nextInt();
total = english + chemistry + computers + physics + maths;
Percentage = (total / 500) * 100;
System.out.println(" Total Marks = " + total);
System.out.println(" Marks Percentage = " + Percentage);
if(Percentage >= 90)
{
System.out.println("\n Grade A");
}
else if(Percentage >= 80)
{
System.out.println("\n Grade B");
}
else if(Percentage >= 70)
{
System.out.println("\n Grade C");
}
else if(Percentage >= 60)
{
System.out.println("\n Grade D");
}
else if(Percentage >= 40)
{
System.out.println("\n Grade E");
}
else
{
System.out.println("\n Fail");
}
}
}

学生成绩示例程序 2
此程序与上述程序相同。但这次,我们创建了一个单独的方法来显示学生成绩。
import java.util.Scanner;
public class StudentGrade1 {
private static Scanner sc;
public static void main(String[] args)
{
int english, chemistry, computers, physics, maths;
sc = new Scanner(System.in);
System.out.print(" Please Enter the Five Subjects Marks : ");
english = sc.nextInt();
chemistry = sc.nextInt();
computers = sc.nextInt();
physics = sc.nextInt();
maths = sc.nextInt();
studentGrade(english, chemistry, computers, physics, maths);
}
public static void studentGrade(int eng, int chem, int com, int phy, int math)
{
float total, Percentage;
total = eng + chem + com + phy + math;
Percentage = (total / 500) * 100;
System.out.println(" Total Marks = " + total);
System.out.println(" Marks Percentage = " + Percentage);
if(Percentage >= 90)
{
System.out.println("\n Grade A");
}
else if(Percentage >= 80)
{
System.out.println("\n Grade B");
}
else if(Percentage >= 70)
{
System.out.println("\n Grade C");
}
else if(Percentage >= 60)
{
System.out.println("\n Grade D");
}
else if(Percentage >= 40)
{
System.out.println("\n Grade E");
}
else
{
System.out.println("\n Fail");
}
}
}
学生成绩输出
Please Enter the Five Subjects Marks : 80 80 70 85 94
Total Marks = 409.0
Marks Percentage = 81.8
Grade B