Create a Time Conversion application that prompts the user for a time in minutes and then displays the time in hours and minutes. Be sure to consider times whether the number of minutes left over is less than 10. For example, 184 minutes in hour:minute format is 3:04 (Hint: use the modulus operator). The application output should look similar to:

Respuesta :

Limosa

Answer:

The following are the program in the Java Programming Language.

//import the following class

import java.util.Scanner;

//define class

public class TimeConversion  

{

 //define main function

 public static void main(String[] args)  

 {

   //create the object of the scanner class

   Scanner s = new Scanner(System.in);

   //print message

   System.out.println("Enter the minutes: ");

   //get input in the variable

   int t=s.nextInt();

   //initialize in the variable

   int hr=t/60;

   //initialize in the variable    

   int min=t%60;

   //declare the string type variable

   String result;

   //initialize in the variable

   result=""+hr;

   //check that the variable is less than 10

   if(min<10)

     //then, initialize this

     result=result +":0"+min;

   //otherwise

   else

     //initialize this

     result=result +":"+min;

   //print the result

   System.out.println(result);

 }

}

Output:

Enter the minutes:

184

3:04

Explanation:

The following are the description in the program.

  • Firstly, import the scanner class and define the class 'TimeConversion', inside the class, we define the main method and inside the main method.
  • Create the object of the scanner class 'c' and then get input from the user in the variable 't' through the scanner class object.
  • Then, declare the variable 'hr' and initialize the value input divided by 60. Declare the variable 'min' and initialize the value input mod by 60.
  • Declare the string data type variable 'result' then, check that the variable 'min' is less than 10 then, initialize the following format in the variable 'result' and otherwise the initialize the other formate in the variable 'result'.
  • Finally, we print the variable 'result'.
ACCESS MORE

Otras preguntas