0

Primitive Operators Java

Students are given homework in math, history, and geometry. Write a program that takes the time spent on each subject as input, and calculates and outputs the total number of hours and minutes spent on each subject, each on a new line accordingly. Sample Input 35 40 39 Sample Output 1 54 Explanation The total amount of spent minutes is 114, which is equal to 1 hour (the first output) and 54 minutes (the second output). The explanation does not match the problem given. The problem states in summary (correct me if I’m wrong) Take 3 separate values as input for the 3 subjects respectively and then print each value out on a separate line for each subject. The sample output shows only two lines as output but not 3. I’m am seriously confused.

4th Mar 2021, 7:15 PM
Deze Tingz
Deze Tingz - avatar
6 odpowiedzi
+ 2
The inputs are time in minutes for 3 subjects.. You need to find total time in hours. So Total 114 (35+40+39)minutes = 1 hr 54 minutes.
4th Mar 2021, 7:24 PM
Jayakrishna 🇮🇳
+ 1
I think Im beginning to understand, I believe I have to use the "modulo" operator to solve this. Thanks for the assistance guys.
4th Mar 2021, 7:29 PM
Deze Tingz
Deze Tingz - avatar
+ 1
This is how I solved it import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int math = scanner.nextInt(); int history = scanner.nextInt(); int geometry = scanner.nextInt(); //your code goes here int totalTimeSpent = math + history + geometry; int hourValue = 60; int firstLineValue = totalTimeSpent / hourValue; int secondLineValue = totalTimeSpent % hourValue; System.out.println(firstLineValue); System.out.println(secondLineValue); } }
4th Mar 2021, 7:36 PM
Deze Tingz
Deze Tingz - avatar
+ 1
That's it. You can make it short.. //your code goes here int total = math + history + geometry; System.out.println(total/60); System.out.println(total%60); You're welcome...
4th Mar 2021, 7:44 PM
Jayakrishna 🇮🇳
+ 1
I know, I just wanted to clearly see what I was doing😄
4th Mar 2021, 8:20 PM
Deze Tingz
Deze Tingz - avatar
0
The part that says how much time spent on it just sounds like GoGuardian
4th Mar 2021, 7:17 PM
BUZZSAW
BUZZSAW - avatar