Computer Programming/Variables/Java

From Wikiversity
Jump to navigation Jump to search

variables.java[edit]

// This program converts a Fahrenheit temperature to Celsius.
//
// References:
//     https://www.mathsisfun.com/temperature-conversion.html
//     https://en.wikibooks.org/wiki/Java_Programming

import java.util.Scanner;

class variables {
    public static void main(String[] args) {
        double f;
        double c;
        
        System.out.println("Enter Fahrenheit temperature:");
        Scanner scanner = new Scanner(System.in);
        f = scanner.nextDouble();

        c = (f - 32) * 5 / 9;

        System.out.println(f + "° Fahrenheit is " + c + "° Celsius");
    }
}

Try It[edit]

Copy and paste the code above into one of the following free online development environments or use your own Java compiler / interpreter / IDE.

See Also[edit]