+ 1

Homework exercise

I tried to answer the question but I could not. These are my attempts 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 minutess spent on each subject, each on a new line accordingly. Sample lInput 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). 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 ma = 35;        int his = 40;        int geo = 39;    } }

18th Oct 2020, 3:14 PM
gamer Bro
gamer Bro - avatar
6 Antworten
+ 4
Can you tell me what is purpose of 3 lines after Scanner object creation and setting values of 3 variables... I think you are not completed lesson.. So first complete lesson and try practice. Jumping farward will make you confuse... You actually need to calculate into hours spent.. Sum all minutes I.e 114 114/60=1 hr 114%60 = 54minutes Now print these calculations...
18th Oct 2020, 3:21 PM
Jayakrishna 🇮🇳
+ 2
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(); int sum = math + history +geometry; int x = sum / 60; int y = sum % 60; System.out.println(x); System.out.println(y); } }
23rd Dec 2021, 3:53 PM
Ali Simsek
+ 1
import java.util.Scanner; public class Practice { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter time spend on each subject in minutes"); System.out.print("Math :"); int math = sc.nextInt(); System.out.print("Geometry :"); int geo = sc.nextInt(); System.out.print("Science :" ); int sci = sc.nextInt(); System.out.println("Time need for homework : " + (math+geo+sci)/60 + "hr" + (math+geo+sci)%60 + "min"); } }
2nd May 2021, 3:02 PM
Rohit
0
Completing Jayakrishna🇮🇳's answer, you can just do a loop 3 times (since we know that the input guaranteed 3 times), and inside of it, sum all of the number inputted. After the loop is done, print out (sum/60 + " " + sum%60). Please don't ask why 60...
18th Oct 2020, 11:01 PM
LastSecond959
LastSecond959 - avatar
0
//The easiest example to get this to work is to type : int totalHours = (math + history + geometry)/60 int totalMins = (math + history +geometry)%60 //then print out the results. System.out.println(totalHours); System.out.println(totalMins); Remember that it is asking for user input with the "int math = scanner.nextInt();" which is already coded for you.
14th Mar 2021, 1:32 PM
Brandon Cook
Brandon Cook - avatar
0
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(); int sum = math + history +geometry; int x = sum / 60; int y = sum % 60; System.out.println(x); System.out.println(y); } } Good Luck
26th Jan 2022, 6:22 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar