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;23public class Main {4 public static void main(String[] args) {5 Scanner sc = new Scanner(System.in);67 System.out.print("Enter temperature in Celsius: ");8 double c = sc.nextDouble();910 double f = (c * 9 / 5) + 32;11 System.out.println("Temperature in Fahrenheit = " + f);1213 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.