Celsius to Fahrenheit in Java

Convert temperature from Celsius to Fahrenheit.

BeginnerModule 1: Basic Java ProgramsExample 14 of 20
celsius-to-fahrenheit.java
1import java.util.Scanner;
2
3public class Main {
4 public static void main(String[] args) {
5 Scanner sc = new Scanner(System.in);
6
7 System.out.print("Enter temperature in Celsius: ");
8 double c = sc.nextDouble();
9
10 double f = (c * 9 / 5) + 32;
11 System.out.println("Temperature in Fahrenheit = " + f);
12
13 sc.close();
14 }
15}

Output

Enter temperature in Celsius: 0
Temperature in Fahrenheit = 32.0

What's going on

We apply the conversion formula: F = (C × 9/5) + 32.