Java Program to Convert Century to Decade and Decade to Century

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

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

Java Program to Convert Century to Decade and Decade to Century

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

Century is a period of 100 years. While Decade is a period of 10 years.

1 Century = 10 Decade
1 Decade = 0.1 Century

Formula to convert Decade to Century.

Century = Decade / 10

Formula to convert Century to Decade.

Decade = Century * 10

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

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

Approach:

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

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

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

Approach:

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

Enter value of century: 
3
Enter value of decade: 
10
Value of 3.0 century in decade: 30.0
Value of 10.0 decade in century: 1.0

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

Approach:

  • Take user input of Century and Decade value.
  • Call a user defined method by passing Century and Decade value as parameter.
  • Inside method convert Century to Decade and Decade to Century 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 century
        System.out.println("Enter value of century: ");  
        double century = 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(century, decade);
   }
   
   //convert() method to convert century to decade and vice versa
   public static void convert(double century, double decade)
   {
        //converting century to decade
        double d = century * 10;
        //converting decade to century
        double c = decade / 10;
        //printing result
        System.out.println("Value of "+century+" century in decade: "+ d);   
        System.out.println("Value of "+decade+" decade in century: "+ c);   
   }
}
Output:

Enter value of century: 
4.5
Enter value of decade: 
16
Value of 4.5 century in decade: 45.0
Value of 16.0 decade in century: 1.6

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: