Menu
Coddy logo textTech

논리 AND

Coddy Dart 여정의 기초 섹션에 포함된 레슨. 94개 중 23번째.

논리 AND 연산자 (&&)는 두 식이 모두 true일 때만 true를 반환하며, 그렇지 않으면 false를 반환합니다.

void main() {
  bool isAdult = true;
  bool hasLicense = true;
  
  bool canDrive = isAdult && hasLicense;
  
  print('Can this person drive? $canDrive');
}
void main() {
  int age = 25;
  double savings = 5000.0;
  
  bool isEligibleForLoan = (age >= 18) && (savings >= 1000.0);
  
  print('Is eligible for loan? $isEligibleForLoan');
}
challenge icon

챌린지

쉬움

논리 AND(&&) 연산자를 사용하여 게임 이용 자격 확인 프로그램을 만드세요:

  1. age라는 이름의 정수형 변수를 선언하고 15의 값을 할당합니다.
  2. hasParentalConsent라는 이름의 불리언 변수를 선언하고 true 값을 할당합니다.
  3. hasCompletedTutorial라는 이름의 불리언 변수를 선언하고 false 값을 할당합니다.
  4. 다음 조건에만 true가 되는 불리언 변수 canPlayGame을 선언합니다:
    • 플레이어가 18세 이상이거나, OR
    • 플레이어가 최소 13세 이상이고 AND 부모의 동의를 받은 경우
  5. 다음 조건에만 true가 되는 불리언 변수 canAccessBonus를 선언합니다:
    • 플레이어가 canPlayGame 상태이고 AND 튜토리얼을 완료한 경우
  6. 정확히 다음과 같은 형식으로 결과를 출력하세요:
Player age: 15
Has parental consent: true
Completed tutorial: false
Can play game: true
Can access bonus content: false

출력 결과는 정확히 이 형식과 일치해야 합니다.

직접 해보기

void main() {
  // 여기에 변수를 선언하세요
  // 플레이스홀더 값을 작업에서 요청하는 값으로 바꾸세요
  int age = 0;
  bool hasParentalConsent = false;
  bool hasCompletedTutorial = false;
  
  // 플레이어가 게임을 플레이할 수 있는지 확인하세요
  // 플레이스홀더 나이를 올바른 임계값으로 바꾸세요
  bool canPlayGame = age >= 0 || (age >= 0 && hasParentalConsent);
  
  // Check if player can access bonus content
  // 플레이스홀더 값을 작업에서 설명하는 조건으로 바꾸세요
  bool canAccessBonus = true;
  
  // 결과를 출력하세요
  print("Player age: $age");
  print("Has parental consent: $hasParentalConsent");
  print("Completed tutorial: $hasCompletedTutorial");
  print("Can play game: $canPlayGame");
  print("Can access bonus content: $canAccessBonus");
}
quiz icon실력 점검

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

기초의 모든 레슨

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