-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentinal.java
More file actions
39 lines (39 loc) · 1013 Bytes
/
Copy pathSentinal.java
File metadata and controls
39 lines (39 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
public class Sentinal
{
public static void main(String[] args)
{
Scanner sc= new Scanner(System.in);
int total =0;
double average;
int grade;
int gradecount=0;
while(true)
{
System.out.println("enter the grades");
grade=sc.nextInt();
if(grade==-1) // sentinal condition
{
break;
}
if(grade<0 ||grade>100)
{
System.out.println("invalid grade");
continue;
}
total+=grade;
gradecount++;
}
if(gradecount > 0)
{
average=total/gradecount;
System.out.println("Total is :"+total);
System.out.println("average grade is:"+average);
}
else
{
System.out.println("no grade you enterd");
}
sc.close();
}
}