-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcaffeine.java
More file actions
26 lines (21 loc) · 1016 Bytes
/
caffeine.java
File metadata and controls
26 lines (21 loc) · 1016 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
import java.util.Scanner;
public class caffeine {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
double caffeineMg; // "double" supports floating-point like 75.5, versus int for integers like 75.
System.out.print("Enter caffeine amount (in mg) : ");
caffeineMg = scnr.nextDouble();
// Declaring variables
double caffeineHalfLife6Hours;
double caffeineHalfLife12Hours;
double caffeineHalfLife18Hours;
// Calculating halflives
caffeineHalfLife6Hours = caffeineMg / 2.0;
caffeineHalfLife12Hours = caffeineHalfLife6Hours / 2.0;
caffeineHalfLife18Hours = caffeineHalfLife12Hours / 2.0;
// Printing outputs
System.out.printf("After 6 hours : " + "%.2f mg\n", caffeineHalfLife6Hours);
System.out.printf("After 12 hours : " + "%.2f mg\n", caffeineHalfLife12Hours);
System.out.printf("After 18 hours : " + "%.2f mg\n", caffeineHalfLife18Hours);
}
}