- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalAverage.java
More file actions
Latest commit
23 lines (18 loc) · 645 Bytes
/
Copy pathcalAverage.java
File metadata and controls
23 lines (18 loc) · 645 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
packageex01;
importjava.util.*;
publicclasscalAverage
{
publicstaticvoidmain(String[] args)
{
// TODO Auto-generated method stub
Scannerscn = newScanner(System.in);
System.out.print("請輸入三個整數,中間用空白間隔: "); // prompt user enter three integers
intiNum1 = scn.nextInt(); // store 1st value
intiNum2 = scn.nextInt(); // store 2nd value
intiNum3 = scn.nextInt(); // store 3rd value
floatfSum = iNum1 + iNum2 + iNum3; // sum
floatfAver = fSum / 3; // calculate average
System.out.printf("%.2f", fAver); // print out the result
scn.close();
} // end main
}