화씨 값을 섭씨 값으로 변환

2024. 7. 16. 21:31정보처리,전산/JAVA

반응형
public class Main {
    public static void main(String[] args) {
        double fahrenheit = 98.6; // 예제 화씨 값
        double celsius = toCelsius(fahrenheit);
        System.out.println("Fahrenheit: " + fahrenheit + " => Celsius: " + celsius);
    }

    public static double toCelsius(double fahrenheit) {
        return 5.0 / 9 * (fahrenheit - 32);
    }
}

 

 

 

 

화씨 온도를 사용자로부터 입력받아 섭씨 온도로 변환

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter temperature in Fahrenheit: ");
        double fahrenheit = scanner.nextDouble();

        double celsius = toCelsius(fahrenheit);
        System.out.println("Fahrenheit: " + fahrenheit + " => Celsius: " + celsius);
        
        scanner.close();
    }

    public static double toCelsius(double fahrenheit) {
        return 5.0 / 9 * (fahrenheit - 32);
    }
}
반응형

'정보처리,전산 > JAVA' 카테고리의 다른 글

생성자 오버라이딩 업캐스팅  (0) 2024.07.26
생성자의 오버로딩 (Overloading)  (0) 2024.07.17
1차 배열 내림차순 정렬  (0) 2024.06.01
2차원 배열  (0) 2024.06.01
ArrayIndexOutOfBoundsException  (0) 2024.05.08