Java Program to Convert Month to Decade and Decade to Month

In the previous article, we have discussed about Java Program to Convert Month to Year and Year to Month

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

Java Program to Convert Month to Decade and Decade to Month

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

Month is a period time used in calendar which is 30 or 31 days long.(For February 28 or 29 days(if Leap year)). While Decade is a period of 10 years.

1 Month = 0.00833334 Decade
1 Decade = 120 Month

Formula to convert Decade to Month.

Month = Decade * 120

Formula to convert Month to Decade.

Decade = Month / 120

Let’s see different ways to convert Month to Decade and Decade to Month.

Method-1: Java Program to Convert Month to Decade and Decade to Month By Using Static Input Value

Approach:

  • Declare Month and Decade value.
  • Then convert Month to Decade and Decade to Month 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);
        //initialized value of month
        double month = 1;
        //initialized value of decade
        double decade = 1;
        
        //converting month to decade
        double de = month / 120;
        //converting decade to month
        double m = decade * 120;
        //printing result
        System.out.println("Value of "+month+" month in decade: "+ de);   
        System.out.println("Value of "+decade+" decade in month: "+ m);   
   }
}
Output:

Value of 1.0 month in decade: 0.008333333333333333
Value of 1.0 decade in month: 120.0

Method-2: Java Program to Convert Month to Decade and Decade to Month By Using User Input Value

Approach:

  • Take user input of Month and Decade value.
  • Then convert Month to Decade and Decade to Month 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 month
        System.out.println("Enter value of month: ");  
        double month = sc.nextDouble();
        //Taking the value input of double variable decade
        System.out.println("Enter value of decade: ");  
        double decade = sc.nextDouble();
        
        //converting month to decade
        double de = month / 120;
        //converting decade to month
        double m = decade * 120;
        //printing result
        System.out.println("Value of "+month+" month in decade: "+ de);   
        System.out.println("Value of "+decade+" decade in month: "+ m);   
   }
}
Output:

Enter value of month: 
250
Enter value of decade: 
8
Value of 250.0 month in decade: 2.0833333333333335
Value of 8.0 decade in month: 960.0

Method-3: Java Program to Convert Month to Decade and Decade to Month By Using User Defined Method

Approach:

  • Take user input of Month and Decade value.
  • Call a user defined method by passing Month and Decade value as parameter.
  • Inside method convert Month to Decade and Decade to Month 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 month
        System.out.println("Enter value of month: ");  
        double month = sc.nextDouble();
        //Taking the value input of double variable decade
        System.out.println("Enter value of decade: ");  
        double decade = sc.nextDouble();
        //calling user defined method convert()
        convert(month, decade);
   }
   
   //convert() method to convert month to decade and vice versa
   public static void convert(double month, double decade)
   {
        //converting month to decade
        double de = month / 120;
        //converting decade to month
        double m = decade * 120;
        //printing result
        System.out.println("Value of "+month+" month in decade: "+ de);   
        System.out.println("Value of "+decade+" decade in month: "+ m);   
   }
}
Output:

Enter value of month: 
34
Enter value of decade: 
1
Value of 34.0 month in decade: 0.2833333333333333
Value of 1.0 decade in month: 120.0

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: