Hi I am trying to make a small temperature converter but I cannot input what unit I'm starting from. What is wrong?
import java.util.Scanner;
public class temperatureConvertor {
public static void main(String[] args) throws InterruptedException {
Scanner sc = new Scanner(System.in);
System.out.println("Hello and thank you for testing this temperature convertor");
Thread.sleep(700);
System.out.println("You can convert from Fahrenheit to Celsius and vice-versa");
Thread.sleep(650);
System.out.println("Let's begin!");
System.out.println();
System.out.println();
System.out.println("Enter a temperature: ");
int temperatureNumber = sc.nextInt();
int newCel = ((temperatureNumber-32) * 5/9);
int newFah = ((temperatureNumber * 9/5) + 32);
Thread.sleep(500);
System.out.println("Is this in fahrenheit or celsius? You can type fahrenheit/f or celsius/c ");
String unit = sc.nextLine();
Thread.sleep(1000);
if(unit.equals("fahrenheit") || unit.equals("f")){
System.out.println("Starting Temperature: " + temperatureNumber + "°F");
Thread.sleep(600);
System.out.println("New Temperature: " + newCel);
}else if(unit.equals("celsius") || unit.equals("c")){
System.out.println("Starting Temperature: " + temperatureNumber + "°C");
Thread.sleep(600);
System.out.println("New Temperature: " + newFah);
}
sc.close();
}
}
Current output looks like that:
I tried to putting the conversion variables before the starting temperature and I tried putting the conversions in each conditonal.