본문 바로가기

코딩테스트/Coding Bat

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

728x90
728x90

https://codingbat.com/prob/p182873

 

CodingBat Java Warmup-1 makes10

Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.makes10(9, 10) → truemakes10(9, 9) → falsemakes10(1, 9) → trueGo...Save, Compile, Run (ctrl-enter)Show Solution

codingbat.com



= 문제 번역 =

2개의 int a와 b가 주어졌을 때, 하나가 10이거나 합이 10이면 true를 반환합니다.

 

= 해설 =

< 1 >
public boolean makes10(int a, int b) {
  if(a==10||b==10) return true;
  if((a+b)==10) return true;
  return false;
}

< 2 >
public boolean makes10(int a, int b) {
  return ((a==10||b==10)||(a+b)==10);
}

 

728x90