Menu
CoddyTech

불리언 조건

Coddy의 Kotlin 개발자를 위한 Dart 코스 레슨. 48개 중 7번째.

Kotlin과 Dart는 Boolean 조건과 단락 논리 연산을 요구합니다. Kotlin의 if는 식인 반면, Dart는 선택 결과로 값을 만들어야 할 때 조건 연산자를 사용합니다.

조건과 논리 피연산자는 bool이어야 합니다. 단락 연산자의 오른쪽은 필요할 때만 실행되므로, 출력이 있는 콜백이 완전히 건너뛰어질 수 있습니다.

Kotlin 전체 프로그램:

fun probe():Boolean{println("probe");return true}
fun main(){println(if(false && probe()) "open" else "closed")}

Dart 전체 프로그램:

bool probe(){print('probe');return true;}
void main(){if(false && probe()){print('open');}else{print('closed');}}
challenge icon

챌린지

쉬움

온도가 10 이상 80 이하이고 문이 닫혀 있을 때만 true가 되는 safe(int temperature, bool doorClosed)를 구현하세요. 입력은 온도와 true 또는 false입니다. 소문자 Boolean 텍스트를 반환하세요.

편집 가능한 파일에서 출력하지 마세요. 제공된 exercise.dart가 입력을 분석하고 출력을 반환합니다. 잠긴 드라이버는 공개 API를 독립적으로 테스트하고 결과를 줄바꿈 하나와 함께 출력합니다.

코드는 functions.dart, exercise.dart에 작성하세요. main.dart에는 제공된 입력/출력 코드가 있으며 수정할 수 없습니다.

직접 해보기

import 'dart:io';
import 'dart:convert';
import 'exercise.dart';
import 'functions.dart';
void check(bool condition){if(!condition)throw StateError('Public API contract failed');}
Future<void> main() async {
final raw=await stdin.transform(utf8.decoder).join();
final input=raw.replaceFirst(RegExp(r'\r?\n$'),'');
check(safe(40,true));check(!safe(40,false));
stdout.writeln(solve(input));
}
quiz icon실력 점검

이 레슨에는 짧은 퀴즈가 포함되어 있습니다. 레슨을 시작해 문제를 풀고 진행 상황을 기록하세요.

Kotlin 개발자를 위한 Dart의 모든 레슨

직접 연습해 보세요: 온라인 Dart 컴파일러