Write a programe to input three marks of a student and determine the average. Print a suitable grade if the average is between;
75-100 – A
75-100 – A
60-74 – B
50-59 – C
0-49 – D
Print an error message if a negative number is entered or if the number is not with in the range from 0 to 100.
class Results {
public static void main(String[] args) {
int x = 35;
int y = 24;
int z = 12;
int average=0;
if (x > 100 | y > 100 | z > 100 | x < 0 | y < 0 | z <0 ) {
System.out.println("The entered number is not with in the range from 0 to 100. Please enter a valid number.");
} else {
average = (x + y + z) / 3;
System.out.println("Average : " + average);
}
if (average>75){
System.out.println("Grade : A");
}else if(average>60){
System.out.println("Grade : B");
}else if(average>50){
System.out.println("Grade : c");
}else if(average>0){
System.out.println("Grade : D");
}
}
}
1 comments:
Write a method, which takes an integer as an argument and returns true if the argument is
an odd number, or false otherwise. Demonstrate the method in a complete program.
Post a Comment