/**
* Convert temperatures
*
* @author (Alex Lee)
* @version (---)
*/
import java.util.*;
public class TempConverter
{
public static void main(String args[]){
Scanner scan = new Scanner(System.in);
boolean keepGoing = true;
double answer;
while(keepGoing){
System.out.println("Please enter a form of temperature (Celcius: 1 or Fahrenheit: 2): ");
int temp = scan.nextInt();
System.out.println("Please enter a temperature: ");
double Num = scan.nextDouble();
if(temp==(1))
System.out.println("ConvertedTemperature: ");
answer = (9.0/5.0 * Num) + 32.0;
System.out.println(answer);
//end of if
if(temp==(2))
System.out.println("ConvertedTemperature: ");
answer = (Num + (-32.0)) * 5.0/9.0;
System.out.println(answer);
//end of if
System.out.println("To continue press 1, any other number to exit");
int cont = scan.nextInt();
if(cont != 1) //! means not = to 1
keepGoing = 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.