날씨 리포터
현재 위치의 일기예보를 가져오는 방법을 찾았어요. 날씨 유형에 따라 어떤 물건을 사용해야 하는지 알려 주는 간단한 프로그램을 만들고 싶어요.
이 연습은 강의의 일부입니다
중급 Java
연습 안내
- 검사할 항목을
case로 만들 수 있도록 올바른 키워드를 사용하세요. "Sunny"일 때만 출력되도록 알맞은 상수를 넣으세요.- 오직 하나의
println()만 실행되도록 올바른 키워드를 작성하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
class WeatherReporter {
public static void main(String[] args) {
String weather = "Sunny";
switch (weather) {
// Use the correct keyword to make it a case to check
____ "Windy":
System.out.println("Take an umbrella");
break;
// Enter the appropriate name to check for sunny
case "____":
System.out.println("Don't forget your sunscreen");
// Write the correct keyword down to make sure the message will be unique
____;
case "Cloudy":
System.out.println("The umbrella might be great");
break;
default:
System.out.println("I don't know what the weather will be like");
}
}
}