Java Program to Convert Minute to Second and Second to Minute

In the previous article we have discussed about Java Program to Convert Second to Millisecond, Microsecond and Vice Versa

In this article we will see how to convert Minute to Second and Second to Minute by using Java programming language.

Java Program to Convert Minute to Second and Second to Minute

Before jumping into the program let’s know the relationship between Minute and Second and how we can convert Minute to Second and vice versa.

Minute and Second are used as unit of time.

1 Minute = 60 Second
1 Second = 0.0166667 Minute

Formula to convert Minute to Second.

Second = Minute * 60

Formula to convert Second to Minute.

Minute = Second / 60

Let’s see different ways to convert Minute to Second and Second to Minute.

Method-1: Java Program to Convert Minute to Second and Second to Minute By Using Static Input Value

Approach:

  • Declare Minute and Second value.
  • Then convert Minute to Second and Second to Minute by using the formula.
  • Print result.

Program:

import java.util.*;
public class Main 
{
   public static void main(String args[])
   {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        //value of minute declared
        double minute = 1;
        //value of second declared 
        double second = 1;

        //converting minute to second
        double sec = minute*60;
        //converting second to minute
        double min = second/60;
        //printing result
        System.out.println("Value of "+minute+" minute in second: "+ sec);   
        System.out.println("Value of "+second+" second in minute: "+ min);   
   }
}
Output:

Value of 1.0 minute in second: 60.0
Value of 1.0 second in minute: 0.016666666666666666

Method-2: Java Program to Convert Minute to Second and Second to Minute By Using User Input Value

Approach:

  • Take user input of Minute and Second value.
  • Then convert Minute to Second and Second to Minute by using the formula.
  • Print result.

Program:

import java.util.*;
public class Main 
{
   public static void main(String args[])
   {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        //Taking the value input of double variable minute
        System.out.println("Enter value of minute: ");  
        double minute = sc.nextDouble();
        //Taking the value input of double variable second
        System.out.println("Enter value of second: ");  
        double second = sc.nextDouble();

        //converting minute to second
        double sec = minute*60;
        //converting second to minute
        double min = second/60;
        //printing result
        System.out.println("Value of "+minute+" minute in second: "+ sec);   
        System.out.println("Value of "+second+" second in minute: "+ min);   
   }
}
Output:

Enter value of minute: 
15
Enter value of second: 
400
Value of 15.0 minute in second: 900.0
Value of 400.0 second in minute: 6.666666666666667

Method-3: Java Program to Convert Minute to Second and Second to Minute By Using User Defined Method

Approach:

  • Take user input of Minute and Second value.
  • Call a user defined method by passing Minute and Second value as parameter.
  • Inside method convert Minute to Second and Second to Minute by using the formula.
  • Print result.

Program:

import java.util.*;
public class Main 
{
   public static void main(String args[])
   {
        //Scanner class object created
        Scanner sc=new Scanner(System.in);
        //Taking the value input of double variable minute
        System.out.println("Enter value of minute: ");  
        double minute = sc.nextDouble();
        //Taking the value input of double variable second
        System.out.println("Enter value of second: ");  
        double second = sc.nextDouble();
        //calling user defined method convert()
        convert(minute, second);
   }
   
   //convert() method to convert minute to second and vice versa
   public static void convert(double minute, double second)
   {
        //converting minute to second
        double sec = minute*60;
        //converting second to minute
        double min = second/60;
        //printing result
        System.out.println("Value of "+minute+" minute in second: "+ sec);   
        System.out.println("Value of "+second+" second in minute: "+ min);   
   }
}
Output:

Enter value of minute: 
5
Enter value of second: 
20
Value of 5.0 minute in second: 300.0
Value of 20.0 second in minute: 0.3333333333333333

The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts.

Related Java Programs: