Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to calculate student grades
The following program accepts average from the user, calculates the grade and prints it.
Example
public class CalculateStudentGrades {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter average of your marks (less than 100)::");
int average = sc.nextInt();
char grade;
if(average>=80){
grade = 'A';
}else if(average>=60 && average<80){
grade = 'B';
}
else if(average>=40 && average<60){
grade = 'C';
}
else {
grade = 'D';
}
switch(grade) {
case 'A' :
System.out.println("Excellent!");
break;
case 'B' :
case 'C' :
System.out.println("Well done");
break;
case 'D' :
System.out.println("You passed");
case 'F' :
System.out.println("Better try again");
break;
default :
System.out.println("Invalid grade");
}
System.out.println("Your grade is " + grade);
}
}
Output
Enter average of your marks (less than 100):: 59 Well done Your grade is C
Advertisements