C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Introduction to Java

Celsius to Fahrenheit conversion - Java Program

Formula used:

F = (C × 9/5) + 32

import java.util.Scanner;

 

public class CelsiusToFahrenheit {

    public static void main(String[] args) {

 

        Scanner sc = new Scanner(System.in);

 

        // Taking Celsius temperature as input

        System.out.print("Enter temperature in Celsius: ");

        double celsius = sc.nextDouble();

 

        // Converting to Fahrenheit using formula

        double fahrenheit = (celsius * 9/5) + 32;

 

        // Displaying result

        System.out.println(celsius + "°C = " + fahrenheit + "°F");

 

        sc.close();

    }

}

Output

 
OUTPUT 1:

Enter temperature in Celsius: 25
25.0°C = 77.0°F

OUTPUT 2:

Enter temperature in Celsius: 0
0.0°C = 32.0°F