/**
* Converts Temperature from Farenheit to Celsius and vice versa.
*
* @EvanZanolli (your name)
* @1.7 (a version number or a date)
*/
import java.util.*;
public class TempConverter
{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
boolean run = true; //making it run over and over
while (run = true){
System.out.print ("Enter a temperature: ");
double myNum = sc.nextInt(); //your temperature
double temp = 0; //declaring the variable here so I can use it later in the two If statements
System.out.println("Press 1 for Farenheit or 2 for Celsius");
double input = sc.nextInt(); //F or C
if(input == 1){//converting to celsius
System.out.println("Original Temperature: "+ myNum +" Farenheit");
temp = (myNum - 32) * 5/9.0;
System.out.println("Converted Temperature: "+ temp +" Celsius");
}
if(input == 2){//converting to farenheit
System.out.println("Original Temperature: "+ temp +" Celsius");
temp = (9.0/5 * myNum) + 32;
System.out.println("Converted Temperature: "+ temp +" Farenheit");
}
System.out.println("Would you like to input a new temperature? 1 for Y, 2 for N");
int SecondInput = sc.nextInt(); //get out of the loop if possible
if (SecondInput == 1){
run = true;
}else{
run = false;
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.