Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Metric{
- public static void main(String [] args){
- Scanner input = new Scanner(System.in);
- double usernum;
- int selec;
- System.out.println("What is the temperature of this room?");
- usernum = input.nextDouble();
- System.out.println("Press 1 to convert from C to F and 2 to convert from F to C");
- selec = input.nextInt();
- if(selec == 1)
- usernum = CtoF(usernum);
- else if(selec == 2)
- usernum = FtoC(usernum);
- else
- System.out.println("Bad input");
- if(selec == 1 || selec == 2)
- System.out.println(usernum);
- }
- public static double FtoC(double a){
- double constant = 5 / 9;
- a = (a - 32) * constant;
- return a;
- }
- public static double CtoF(double a){
- double constant = 9 / 5;
- a = a * constant + 32;
- return a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement