Temperature Converter DavidH

* David Huang */ /** * This class converts F to C or C to F * @author (David Huang) * @version (1.0) */ import java.util.Scanner; public class Fahrenheit_Celsius { public static void main(String[] args) { while (true) { Scanner s = new Scanner(System.in);//first scanner to input initial temp System.out.print("Enter temperature:"); int nextInt = s.nextInt(); System.out.print("Type 1 if temp is in Celsius, or type 2 if fahrenheit: "); //second scanner to determine celsius or farenheit int corf = s.nextInt(); if (corf == 1) { double fa = (9.0/5 * nextInt) + 32; //equation for celsius to farenheit System.out.println(f + "Fahrenheit"); } else { double ce = (nextInt - 32) * (5.0/9); //equation for farenheit to celsius System.out.println(ce + "" + "Celsius"); } System.out.print("To scan another, please press 1, or press 0 to close the program");//last scanner to ask user if they want to repeat int last = s.nextInt(); if (last != 1) { break; } } } }

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.