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.

6 Answers

+ 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.

+ 1

I think Im beginning to understand, I believe I have to use the "modulo" operator to solve this. Thanks for the assistance guys.

+ 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);
}
}

+ 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...

+ 1

I know, I just wanted to clearly see what I was doing😄

0

The part that says how much time spent on it just sounds like GoGuardian

Hot today

I have made a calculator in which my % (Percentage) not work correctly for 100%50 or 100%20.

0 Votes

Тренажер кода

0 Votes

Python palindrome challenge.

1 Votes

Java

0 Votes