본문 바로가기

코딩테스트/Coding Bat

[코딩뱃] [자바] Warmup - 1단계 : in3050 문제

728x90
728x90

https://codingbat.com/prob/p132134

 

CodingBat Java Warmup-1 in3050

Given 2 int values, return true if they are both in the range 30..40 inclusive, or they are both in the range 40..50 inclusive.in3050(30, 31) → truein3050(30, 41) → falsein3050(40, 50) → trueGo...Save, Compile, Run (ctrl-enter)Show Solution

codingbat.com



= 문제 번역 =

2개의 int 값이 주어지면 둘 다 30..40 범위에 있거나 둘 다 40..50 범위에 있으면 true를 반환합니다.

 

= 문제푸는 팁 =

X

 

= 해설 =

public boolean in3050(int a, int b) {
  if (a >= 30 && a <= 40 && b >= 30 && b <= 40) {
    return true;
  }
  if (a >= 40 && a <= 50 && b >= 40 && b <= 50) {
    return true;
  }
  return false;
  // This could be written as one very large expression,
  // connecting the two main parts with ||
}

728x90