TemperatureConverter

/** * Program to convert temperatures from celsius to fahrenheit or fahrenheit to celsius * * @author Raunaq Singh * @version 1.0 */ import java.util.*; public class TempConverter { public static void main(String args[]){ int loop = 1; //keep the program running after one temp convert while (loop == 1){ Scanner scan = new Scanner(System.in); System.out.println("Please enter a temperature: "); double input = scan.nextInt(); System.out.println("Enter 1 to Convert from C° to F°, or 2 to Convert from F° to C°: "); int choose = scan.nextInt(); if(choose == 1){ input = (input * 9.0/5) + 32; //equation for C to F } else if(choose == 2){ input = ((input - 32) * 5)/9.0; //equation for F to C } System.out.println(input); System.out.println("To convert again, press 1. To quit, press 2."); int quit = scan.nextInt(); //option to keep going or to stop the program if (quit == 1){ loop = 1; } else if (quit == 2){ System.exit(0); } } } }

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.