[자바 연산자] 13. 섭씨온도 문제 (2가지 변환 중 사용자가 선택)

김건우's avatar
Feb 04, 2025
[자바 연산자] 13. 섭씨온도 문제 (2가지 변환 중 사용자가 선택)
package ex02; import java.util.Scanner; public class Temp3 { public static void main(String[] args) { // 식1 c = (f - 32) * 5 / 9 // 식2 f = (c * 9 / 5) + 32 System.out.println("====================="); System.out.println("1. 화씨->섭씨 "); System.out.println("2. 섭씨->화씨 "); System.out.println("====================="); System.out.println("번호를 선택하시오: "); // 화씨 혹은 섭씨 선택하는 코드 Scanner sc = new Scanner(System.in); int n = sc.nextInt(); // 1을 골랐을 때 화씨 -> 섭씨로 변환하는 코드 if (n == 1) { System.out.println("화씨온도를 입력하시오: "); double f = sc.nextDouble(); double c = (f - 32) * 5 / 9; // 섭씨온도 모니터 출력 System.out.println("섭씨온도는 " + c); } // 2(가 아닌 다른 수)를 골랐을 때 섭씨 ->로 변환하는 코드 else { System.out.println("섭씨온도를 입력하시오: "); double c = sc.nextDouble(); double f = (c * 9 / 5) + 32; // 화씨온도 모니터 출력 System.out.println("화씨온도는 " + f); } } }
  • 화씨 > 섭씨
notion image
  • 섭씨 > 화씨
notion image
Share article

gunwoo