0
import java.util.Scanner;
public class TempConversion2{
public static void main(String[] args){
  Scanner in = new Scanner(System.in);
  if (isCelsius()){
     System.out.println("Enter degrees(Celsius): ");
     double celsius = in.nextDouble();
     double fahren = convertToFahren(celsius);
     System.out.printf("%.0f degrees(C) is equal to %.2f degrees(F)", celsius, fahren); 
  } else {
     System.out.println("Enter degrees(Fahrenheit): ");
     double fahren = in.nextDouble();
     double celsius = convertToCelsius(fahren);
     System.out.printf("%.0f degrees(F) is equal to %.2f degrees(C)", fahren, celsius);
  }
}
public static boolean isCelsius(){
  Scanner in = new Scanner(System.in);
  System.out.println("Celsius(C) or Fahrenheit(F): ");
  String degrees = in.nextLine().toUpperCase();
  if (degrees.equals("C")){
     return true;
  } 
  return false;
}
public static double convertToCelsius(double fahren){
  double celsius = (5 / 9) * (fahren - 32);
  return celsius;
}
public static double convertToFahren(double celsius){
  double fahren = 9 / 5 * celsius + 32;
  return fahren; 
}
}

When I enter a fahrenheit number which would make the celsius be negative it only prints out -0.00 & I don't know what's wrong with the code, is it because I'm using printf? or is it because I used double

0 Answers0