Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
import java.util.Scanner;
public class TempConverter{
public static void main(String [] args)
{
float f, c;
f = c = 0;
int a;
Scanner scan = new Scanner (System.in);
System.out.println("Press 1 for C->F or 2 for F->C");
a = scan.nextInt();
if (a == 1)
convertCtoFAndPrint();
else
convertFtoCAndPrint();
}
public static void convertFtoCAndPrint()
{
f = c = 0;
Scanner scan = new Scanner (System.in);
System.out.println("Please enter degrees F");
f = scan.nextFloat();
c = (5/9)*(f-32);
System.out.println(f + " degrees F is " + c + " degrees C.");
}
public static void convertCtoFAndPrint()
{
Scanner scan = new Scanner (System.in);
System.out.println("Please enter degrees C");
c = scan.nextFloat();
f = c*(9/5)+32;
System.out.println(c + " degrees C is " + f + " degrees F.");
}
}
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more