Temp Converter

/** * Charlotte Weisman * Temperature Converter * 9/7/17 */ import java.util.*; public class TempConverter { public static void main(String args[]){ Scanner scan = new Scanner(System.in); boolean keepGoing = true ; while(keepGoing) { System.out.println("Please enter a temperature: "); //input temperature to be converted double myTemp = scan.nextDouble(); //declare temperature variable System.out.println("Enter 1 to convert from C to F, enter 2 to convert from F to C: "); int CF = scan.nextInt(); if(CF==1){ //if variable is 1, convert from C to F double resultF = myTemp * 9.0 / 5 + 32; //convert and print temperature System.out.println(resultF); //print out result }else{ double resultC = (myTemp - 32) * 5 / 9; //convert and print temperature System.out.println(resultC); //print out result } System.out.println("Press 1 to convert another temperature. Press any other number to exit."); //prompt user to convert another temp int cont = scan.nextInt(); if(cont !=1){ keepGoing = false; } } //end of main method }}; //end of class

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.