我怎么打印负双?

时间:2017-02-23 03:11:09

标签: java methods

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; 
}
}

当我输入华氏数字会使摄氏温度变为负数时,它只打印出来            -0.00&我不知道代码有什么问题,是因为我使用的是printf吗?还是因为我使用了双

0 个答案:

没有答案