Simple java program to do temperature conversions.
Code
import java.util.Scanner;
class fun
{
double ftoc(double f)
{
double c;
c=0.56*(f-32);
return c;
}
double ctof(double c)
{
double f;
f=1.8*c+32;
return f;
}
}
public class TempConvertor
{
public static void main(String[] args)
{
fun f=new fun();
Scanner s=new Scanner(System.in);
double ans;
ans=0;
int ch;
System.out.println("ENTER YOUR CHOICE\n 1.Fahrenheit to celcius\n 2.Celcius to Fahrenheit");
ch=s.nextInt();
switch(ch)
{
case 1: System.out.println("ENTER TEMP");
double fah=s.nextDouble();
ans=f.ftoc(fah);
break;
case 2: System.out.println("ENTER TEMP");
double cel=s.nextDouble();
ans=f.ctof(cel);
break;
}
System.out.println("ANSWER IS:"+ans);
System.out.println("THANK YOU");
}
}
Output
Link for Download
http://goo.gl/757WLG
No comments:
Post a Comment