Programmers learn & share
0 votes
63 views

Problem :

I have following question 
complete the method definition to output the hours given minutes. output for sample program: 3.5
by (6.9k points)   | 63 views

2 Answers

0 votes

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)));
   }
by (36.1k points)  
0 votes

Solution:

Follow the below program i hope you will slove this problem

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("");
   }
}

 

by (11.2k points)  
2,227 questions
2,734 answers
59 comments
241 users