/**
* Convert temperatures
*
* @author (Josh Wang)
* @version (09/12/17)
*/
import java.util.*;
public class TempConverter
{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
boolean againPlease = true;
double output = 0;
while(againPlease){
System.out.println("\nPlease select conversion type.");
System.out.println("1. Centigrade to Fahrenheit");
System.out.println("2. Fahrenheit to Centigrade");
int temp = scan.nextInt();
System.out.println("\nPlease enter a temperature:");
double input = scan.nextDouble();
if(temp == 1){
output = (9.0/5.0 * input) + 32.0;
System.out.println("\n" + input +"°C = " + output + "°F.");
}
if(temp == 2){
output = (input + (-32.0)) * 5.0/9.0;
System.out.println("\n" + input +"°F = " + output + "°C.");
}
System.out.println("To continue, press 1. Press any other key to exit.");
int proceed = scan.nextInt();
if(proceed != 1)
againPlease = false;
}//end of while
}//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.