-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComputeGrade.java
More file actions
29 lines (24 loc) · 921 Bytes
/
Copy pathComputeGrade.java
File metadata and controls
29 lines (24 loc) · 921 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
/*
* ComputeGrade.java
* Dave Sullivan (dgs@cs.bu.edu)
*
* This program computes a grade as a percentage.
*/
public class ComputeGrade {
public static void main(String[] args) {
int pointsEarned = 13;
int possiblePoints = 15;
// Compute and print the grade as a percentage.
double grade;
// This line doesn't work, because we get integer division:
// grade = pointsEarned / possiblePoints * 100;
//grade = (double)pointsEarned / possiblePoints * 100;
// This line doesn't work either, because the division is
// evaluated first:
// grade = pointsEarned / possiblePoints * 100.0;
// Instead, we need to use a type cast:
grade = (double)pointsEarned / possiblePoints * 100;
System.out.println("The grade as a percentage is:");
System.out.println(grade);
}
}