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'.
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
Post a Comment