Logic-1
public boolean cigarParty(int cigars, boolean isWeekend) {
if (isWeekend == false && cigars >= 40 && cigars <= 60) {
return true;
} else if (isWeekend == true && cigars >= 40) {
return true;
}
return false;
}
public int dateFashion(int you, int date) {
if (you <= 2 || date <= 2) {
return 0;
} else if (you >= 8 || date >= 8) {
return 2;
} else if (you >= 3 || date >= 3) {
return 1;
}
return 0;
}
public boolean squirrelPlay(int temp, boolean isSummer) {
if (isSummer) {
if (temp >= 60 && temp <= 100) {
return true;
}
}
if (!isSummer) {
if (temp >= 60 && temp <= 90) {
return true;
}
}
return false;
}
public int caughtSpeeding(int speed, boolean isBirthday) {
if (isBirthday) {
if (speed <= 65) {
return 0;
} else if (speed >= 66 && speed <= 85) {
return 1;
} else if (speed >= 86) {
return 2;
}
}
if (!isBirthday) {
if (speed <= 60) {
return 0;
} else if (speed >= 61 && speed <= 80) {
return 1;
} else if (speed >= 81) {
return 2;
}
}
return 0;
}
public int sortaSum(int a, int b) {
int sum = a + b;
if (sum >= 10 && sum <= 19) {
return 20;
}
return sum;
}
public String alarmClock(int day, boolean vacation) {
if (vacation) {
if (day >= 1 && day <= 5) {
return "10:00";
} else {
return "off";
}
}
if (!vacation) {
if (day >= 1 && day <= 5) {
return "7:00";
} else {
return "10:00";
}
}
return "";
}
public boolean love6(int a, int b) {
int sum = a + b;
int diff = a - b;
diff = Math.abs(diff);
return (sum == 6 || diff == 6 || a == 6 || b == 6);
}
public boolean in1To10(int n, boolean outsideMode) {
if(outsideMode){
if(n<=1 || n>=10){
return true;
}
}else if(!outsideMode){
if(n>=1 && n<=10){
return true;
}
}
return false;
}
public boolean specialEleven(int n) {
if (n % 11 == 0 || n % 11 == 1) {
return true;
}
return false;
}
public boolean more20(int n) {
return n % 20 == 1 || n % 20 == 2;
}
public boolean old35(int n) {
if (n % 3 == 0 && n % 5 != 0) {
return true;
} else if (n % 3 != 0 && n % 5 == 0) {
return true;
}
return false;
}
public boolean less20(int n) {
return (n % 20 == 19 || n % 20 == 18);
}
public boolean nearTen(int num) {
if (num % 10 == 9 || num % 10 == 8 || num % 10 == 0) {
return true;
} else if (num % 10 == 1 || num % 10 == 2 || num % 10 == 0) {
return true;
}
return false;
}
public int teenSum(int a, int b) {
int sum = a + b;
if ((a <= 19 && a >= 13) || (b <= 19 && b >= 13)) {
return 19;
}
return sum;
}
public boolean answerCell(boolean isMorning, boolean isMom, boolean isAsleep) {
if (isAsleep) {
return false;
}
if (isMorning) {
return isMom;
}
return true;
}
public int teaParty(int tea, int candy) {
if (tea < 5 || candy < 5) {
return 0;
} else if (tea < 2 * candy && candy < 2 * tea) {
return 1;
}
return 2;
}
public String fizzString(String str) {
if (str.charAt(0) == 'f' && str.charAt(str.length() - 1) == 'b') {
return "Fizz" + "Buzz";
}
if (str.charAt(0) == 'f') {
return "Fizz";
}
if (str.charAt(str.length() - 1) == 'b') {
return "Buzz";
}
return str;
}
public String fizzString2(int n) {
boolean div3 = n % 3 == 0;
boolean div5 = n % 5 == 0;
if (div3 == false && div5 == false) {
return n + "!";
} else if (div3 == true && div5 == false) {
return "Fizz!";
} else if (div3 == false && div5 == true) {
return "Buzz!";
}
return "FizzBuzz!";
}
public boolean twoAsOne(int a, int b, int c) {
return (a + b == c || a + c == b || b + c == a);
}
public boolean inOrder(int a, int b, int c, boolean bOk) {
if (bOk) {
if (c > b) {
return true;
}
}
if (!bOk) {
if (b > a && c > b) {
return true;
}
}
return false;
}
public boolean inOrderEqual(int a, int b, int c, boolean equalOk) {
if (equalOk) {
if (b >= a && c >= b) {
return true;
}
}
if (!equalOk) {
if (b > a && c > b) {
return true;
}
}
return false;
}
public boolean lastDigit(int a, int b, int c) {
if (a % 10 == b % 10 || a % 10 == c % 10 || b % 10 == c % 10) {
return true;
}
return false;
}
public boolean lessBy10(int a, int b, int c) {
if(Math.abs(a-b) >= 10){
return true;
}else if(Math.abs(b-c) >= 10){
return true;
}else if(Math.abs(a-c) >=10){
return true;
}
return false;
}
public int withoutDoubles(int die1, int die2, boolean noDoubles) {
int sum = die1 + die2;
if (noDoubles) {
if (die1 == die2 && die1 <= 5) {
return sum + 1;
} else if (die1 == die2 && die1 == 6) {
return die1 + 1;
}
}
return sum;
}
public int maxMod5(int a, int b) {
if (a == b) {
return 0;
} else if (a % 5 == b % 5) {
return Math.min(a, b);
}
return Math.max(a, b);
}
public int redTicket(int a, int b, int c) {
if (a == 2 && b == 2 && c == 2) {
return 10;
} else if (a == b && b == c && a == c) {
return 5;
} else if (b != a && c != a) {
return 1;
}
return 0;
}
public int greenTicket(int a, int b, int c) {
if (a == b && b == c && a == c) {
return 20;
} else if (a != b && b != c && a != c) {
return 0;
} else if ((a == b && b != c) || (b == c && a != c) || (a == c && b != c)) {
return 10;
}
return a;
}
public int blueTicket(int a, int b, int c) {
int sumAb = a + b;
int sumBc = b + c;
int sumAc = a + c;
if (sumAb == 10 || sumBc == 10 || sumAc == 10) {
return 10;
} else if (sumAb - sumBc == 10 || sumAb - sumAc == 10) {
return 5;
}
return 0;
}
public boolean shareDigit(int a, int b) {
if (a / 10 == b / 10 || a / 10 == b % 10) {
return true;
} else if (a % 10 == b / 10 || a % 10 == b % 10) {
return true;
}
return false;
}
public int sumLimit(int a, int b) {
int sum = a + b;
String strSum = String.valueOf(sum);
String strA = String.valueOf(a);
if (strSum.length() == strA.length()) {
return sum;
} else {
return a;
}
Last updated