Temperature Converter

mport java.util.*; public class TempConverter { public static void main(String args[]){ { Scanner scan = new Scanner(System.in); System.out.println("Please enter a temperature: "); int enteredTemp = scan.nextInt(); System.out.println("Enter 1 for Fahrenheit to Celcius or 2 for Celsius to Fahrenheit"); int decider = scan.nextInt(); if (decider == 1){ double fanswer = (enteredTemp - 32) * 5/9.0; System.out.println(fanswer); }else{ double canswer = (9.0/5 * enteredTemp) + 32; System.out.println(canswer); } boolean restart = true; while (restart){ System.out.println("If you would like to repeat the converter press 1 to exit press 2"); int restartconvert = scan.nextInt(); if (restartconvert == 1){ restart = true; Scanner scan1 = new Scanner(System.in); System.out.println("Please enter a temperature: "); int enteredTemptwo = scan.nextInt(); System.out.println("Enter 1 for Fahrenheit to Celcius or 2 for Celsius to Fahrenheit"); int decider1 = scan.nextInt(); if (decider == 1){ double fanswer1 = (enteredTemptwo - 32) * 5/9.0; System.out.println(fanswer1); }else{ double canswer1 = (9.0/5 * enteredTemptwo) + 32; System.out.println(canswer1); } }else{ restart = false; System.out.println("Thank you for playing"); } } } } }
Temperature Converter

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.