Fahrenheit to Celsius conversion yields only 0.0 and -0.0

后端 未结 5 1942
不思量自难忘°
不思量自难忘° 2020-12-02 01:06

I\'m on the 8th chapter (Methods, Constructors, and Fields) of my Java methods book and I\'m having a problem with one of my exercises.

The provided code is Tempera

5条回答
  •  心在旅途
    2020-12-02 01:44

    import java.util.Scanner;
    public class HelloWorld {
    
        public static void main(String[] args) {
            Scanner reader = new Scanner(System.in);  // Reading from System.in
    
            System.out.println("Enter  the number of Fahrenheit temperatures to convert to Kelvins");
    // opts for the user to enter a number 
    
            int F = reader.nextInt() ; // Scans the next token of the input
            double f = 5/9d;
            System.out.println(f);
            double x = F -32;
            System.out.println(x);
            double K = (f*x)+ 273.0; // the formulae to calculate temperature  in Kelvin
            System.out.println( +F + " Fahrenheit is equal " +K + " Kelvins" ) ;
            reader.close();
    
    
    
    
        }       
    
    }
    

提交回复
热议问题