Convert temperature Celsius to Kelvin


Convert temperature in degree Celsius to Kelvin

Different Method like 'Calculate' and the setter method 'setc' is defined in a class called 'Conversion' and the main method is defined in another class named 'Test'.
In this program getter method is used to set the value in the variable c. And the value is passed as an argument form another method from the main method.

Here is the program written inside the class 'Calculate'.

Methods are either return type or Non-return type. If a void is used in syntax then it is Non-return type and if Data types like(int, String, Double) are used instead of void then it is called a return type method. so, to return value of the variable k the method the keyword 'return' is used. 

public class Conversion
{
    double c;
    double k;
    public void setc(double c)
    {
        this.c=c;
    }
    public double calculate()
    {
        k=c+273.15;
        return k;
    }
}   

And the main function written inside the Test class is.

public class Test
{
    public static void main(String []args)
    {
        Conversion c = new Conversion();
        c.setc(60.0);
        double a= c.calculate();
        
        System.out.println(c.c+" degree celsius to kelvin is "+a);
    }
}





The output of this program seems like this:-



Comments

Popular posts from this blog

Java program using Scanner Class

Java Program to make a comparison between numbers

Calculate the area of Rectangle Using Constructor Overloading rules