Change Temprature From Farenhight To Celcius Conversion or vise versa Program In Java

import java.util.*;

public class FarenhightToCelciusConversion {

static double ftoc(double temp)
{
double celcius;
celcius=(temp-32)*(5.0/9.0);
return celcius;
}

static double ctof(double temp)
{
double fahrenheit;
fahrenheit=temp*(9.0/5.0)+32.0;
return fahrenheit;
}

static double convert(double temp , String tempValue)
{
if(tempValue.equalsIgnoreCase("C"))
{
return (temp-32)*(5.0/9.0);
}
else
{
return temp*(9.0/5.0)+32.0;
}
}

public static void main(String[] args) {


Scanner scn =new Scanner(System.in);
System.out.println("Enter Temp to convert :  ");
double temp=scn.nextDouble();
System.out.println("Enter type to convert to C or F (type f to convert temprature in fahrenhiet or c to convert temprature in celcious) ");

String type=scn.next();
System.out.println("now converted temp is " +convert(temp, type));


}

}

Post a Comment

Previous Post Next Post