# Java Program to Convert Year to Decade and Decade to Year

## Java Program to Convert Year to Decade and Decade to Year

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

Year is a time period of 12 months starting from January to December. While Decade is a period of 10 years.

1 Year = 0.1 Decade
1 Decade = 10 Year

Formula to convert Decade to Year.

Year = Decade * 10

Formula to convert Year to Decade.

Decade = Year / 10

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

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

Approach:

• Declare Year and Decade value.
• Then convert Year to Decade and Decade to Year 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 year
double year = 1;

double d = year / 10;
double y = decade * 10;
//printing result
System.out.println("Value of "+year+" year in decade: "+ d);
}
}
Output:

Value of 1.0 year in decade: 0.1
Value of 1.0 decade in year: 10.0


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

Approach:

• Take user input of Year and Decade value.
• Then convert Year to Decade and Decade to Year 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 year
System.out.println("Enter value of year: ");
double year = sc.nextDouble();
//Taking the value input of double variable decade

double d = year / 10;
double y = decade * 10;
//printing result
System.out.println("Value of "+year+" year in decade: "+ d);
}
}
Output:

Enter value of year:
12
2
Value of 12.0 year in decade: 1.2
Value of 2.0 decade in year: 20.0


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

Approach:

• Take user input of Year and Decade value.
• Call a user defined method by passing Year and Decade value as parameter.
• Inside method convert Year to Decade and Decade to Year 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 year
System.out.println("Enter value of year: ");
double year = sc.nextDouble();
//Taking the value input of double variable decade
//calling user defined method convert()
}

//convert() method to convert year to decade and vice versa
public static void convert(double year, double decade)
{
double d = year / 10;
double y = decade * 10;
//printing result
System.out.println("Value of "+year+" year in decade: "+ d);
}
}
Output:
Enter value of year:
24