# complete the method definition to output the hours given minutes. output for sample program: 3.5

2.2k views

## Problem :

I have following question
complete the method definition to output the hours given minutes. output for sample program: 3.5

## Solution :

One can also use the TimeUnit class

One could define as following

`private static final String FORMAT = "%02d:%02d:%02d";`
Also can have a method like following:

```public static String parseDateTime(long milliseconds) {
return String.format(FORMAT,
TimeUnit.MILLISECONDS.toHours(milliseconds),
TimeUnit.MILLISECONDS.toMinutes(milliseconds) - TimeUnit.HOURS.toMinutes(
TimeUnit.MILLISECONDS.toHours(milliseconds)),
TimeUnit.MILLISECONDS.toSeconds(milliseconds) - TimeUnit.MINUTES.toSeconds(
TimeUnit.MILLISECONDS.toMinutes(milliseconds)));
}```
38.6k points

## Solution:

### Code:

``````/*
Challenge 3.2.2: Basic method call.

Complete the method definition to output the hours given minutes. Output for sample program:
3.5
*/
public class HourToMinConv {
public void outputMinutesAsHours(double origMinutes) {

double minutesInHour = 60.0;
System.out.print(origMinutes / minutesInHour);
}

public static void main (String [] args) {
HourToMinConv timeConv = new HourToMinConv();
// test by running with 210.0, 3600.0, and 0.0.
timeConv.outputMinutesAsHours(210.0);
System.out.println("");
}
}``````

31.7k points

## Related questions

1 answer 447 views
447 views
Convert seconds to hours, minutes and seconds #include <cstdio> #include <iostream> using namespace std; int main() {      int seconds, hours, minutes;      cin >> seconds;      hours = seconds/3600;      cout << seconds << "seconds is equivalent to" << ... know how to fix this? Whenever I do a number less than 3600, a message appears on the screen stating that the program has stopped working.
1 answer 31 views
31 views
Problem: complete the method definition to output the hours given minutes. output for sample program:
1 answer 44 views
44 views
Problem: Someone assist me please : Complete the function definition to output the hours given minutes. output for sample program:
1 answer 13 views
13 views
Problem: I need to convert minutes to hours and minutes in java. For example 260 should be 4:20. can anyone help me how to do convert it.
1 answer 16 views
16 views
Problem: Where should I look for help with this issue : Complete the function definition to output the hours given minutes?
1 answer 16 views
16 views
Problem: How do I complete this recursive function at output_string += ? Output should be: 5! = 5 * 4 * 3 * 2 * 1 = 120 def print_factorial(fact_counter, fact_value): output_string = '' if fact_counter == 0: # Base case: 0! = 1 output_string ... next_counter * fact_value output_string += return output_string user_val = 5 print('%d! = ' % user_val, end="") print(print_factorial(user_val, user_val))
1 answer 214 views
214 views
Problem: write code to complete printfactorial()'s recursive case. sample output if userval is 5: