import java.util.Scanner;
public class Temp{
public static void main (String [] args) {
int x = 1;
while( x== 1){
//°F to °C Deduct 32, then multiply by 5, then divide by 9
//°C to °F Multiply by 9, then divide by 5, then add 32
System.out.println("Enter degrees");
Scanner tempscan = new Scanner(System.in);
double degrees = tempscan.nextDouble();
System.out.println("Enter F or C unit of measurement starting point");
Scanner typescan = new Scanner(System.in);
String temp = typescan.nextLine();
double calc = 0;
double calc2=0;
if(temp.equals("F")){
calc= ((degrees - 32) * 5)/9.0;
System.out.println("Temp is: " + calc);
}else{
calc2=((degrees * 9) / 5) +32;
System.out.println("Temp is: " + calc2);
}
System.out.println(" Press 1 to do another temperature, 2 to cancel");
Scanner sc=new Scanner(System.in);
x=sc.nextInt();
if (x == 2)
System.out.println("Thanks for playing!");
}}}
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.