国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

CodeBat Java Warmup-1

2019-11-06 06:27:09
字體:
來源:轉載
供稿:網友
1.sleepIn
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return true if we sleep in.sleepIn(false, false) → truesleepIn(true, false) → falsesleepIn(false, true) → true   答案:
public boolean sleepIn(boolean weekday, boolean vacation) {  if(weekday == true && vacation == false ){    return false;  }else{    return true;  }}2.monkeyTrouble
We have two monkeys, a and b, and the parameters aSmile and bSmile indicate if each is smiling. We are in trouble if they are both smiling or if neither of them is smiling. Return true if we are in trouble.monkeyTrouble(true, true) → truemonkeyTrouble(false, false) → truemonkeyTrouble(true, false) → false 答案:
public boolean monkeyTrouble(boolean aSmile, boolean bSmile) {  if(aSmile == bSmile){    return true;  }  return false;}3.sumDouble
Given two int values, return their sum. Unless the two values are the same, then return double their sum.sumDouble(1, 2) → 3sumDouble(3, 2) → 5sumDouble(2, 2) → 8答案:
public int sumDouble(int a, int b) {  return (a==b)?2*(a+b):a+b;}4.diff21
Given an int n, return the absolute difference between n and 21, except return double the absolute difference if n is over 21.diff21(19) → 2diff21(10) → 11diff21(21) → 0答案:
public int diff21(int n) {  return (n-21)>0?2*(n-21):Math.abs(n-21);}5.parrotTrouble
We have a loud talking parrot. The "hour" parameter is the current hour time in the range 0..23. We are in trouble if the parrot is talking and the hour is before 7 or after 20. Return true if we are in trouble.parrotTrouble(true, 6) → trueparrotTrouble(true, 7) → falseparrotTrouble(false, 6) → false答案:
public boolean parrotTrouble(boolean talking, int hour) {  if( talking && (hour < 7 ||  hour > 20) ){    return true;  }    return false;}

6.makes10

Given 2 ints, a and b, return true if one if them is 10 or if their sum is 10.

makes10(9, 10) → true

makes10(9, 9) → false

makes10(1, 9) → true

答案:

public boolean makes10(int a, int b) {  return ( a + b ==10 || a == 10 || b == 10)?true:false;}

7.nearHundred

Given an int n, return true if it is within 10 of 100 or 200. Note: Math.abs(num) computes the absolute value of a number.

nearHundred(93) → true

nearHundred(90) → true

nearHundred(89) → false

答案:

public boolean nearHundred(int n) {  return (Math.abs(n-100) <= 10 || Math.abs(n-200) <= 10)?true:false;}

8.posNeg

Given 2 int values, return true if one is negative and one is positive. Except if the parameter "negative" is true, then return true only if both are negative.

posNeg(1, -1, false) → true

posNeg(-1, 1, false) → true

posNeg(-4, -5, true) → true

答案:


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 仁布县| 南安市| 玉树县| 永新县| 金阳县| 临汾市| 类乌齐县| 淄博市| 上犹县| 陇川县| 林芝县| 荣昌县| 全州县| 安化县| 临湘市| 云阳县| 周宁县| 宜川县| 灵山县| 昭苏县| 伊川县| 阿图什市| 鄄城县| 吉隆县| 休宁县| 浮山县| 盘山县| 古蔺县| 平昌县| 比如县| 广宗县| 金华市| 当阳市| 靖江市| 尼玛县| 连南| 广平县| 北流市| 类乌齐县| 航空| 太谷县|