40 f to c code example

Example 1: fahrenheit to celsius formula

cels = (fahr - 32.0) * 5.0/9.0; //Fahr to cels
fahr = (cels * 9.0/5.0) + 32.0; //Cels to fahr

Example 2: convert fahrenheit to celsius

import java.util.Scanner;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int far = sc.nextInt();
        int cel = (far - 32) * 5/9;
        System.out.printf("%d Fahrenheit is %d Celsius", far, cel);
    }
}

Example 3: c to f

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

Example 4: 14 f to c

14°F = -10°C

Tags:

Java Example