π
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
public boolean posNeg(int a, int b, boolean negative) { | |
if(a<0 && b>0 && negative==false){ | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Given a string, take the last char and return a new string with the last char added at the front and back, so "cat" yields "tcatt". The original string will be length 1 or more. | |
//backAround("cat") β "tcatt" | |
//backAround("Hello") β "oHelloo" | |
//backAround("a") β "aaa | |
public String backAround(String str) { | |
int length = str.length(); | |
char length1 = str.charAt(length-1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Given two int values, return their sum. Unless the two values are the same, then return double their sum. | |
//sumDouble(1, 2) β 3 | |
//sumDouble(3, 2) β 5 | |
//sumDouble(2, 2) β 8 | |
public int sumDouble(int a, int b) { | |
if(a==b){ | |
return ((a+b)*2); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) β 2 | |
//diff21(10) β 11 | |
//diff21(21) β 0 | |
public int diff21(int n) { | |
if(n<=21){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Given 2 positive int values, return the larger value that is in the range 10..20 inclusive, or return 0 if neither is in that range. | |
//max1020(11, 19) β 19 | |
//max1020(19, 11) β 19 | |
//max1020(11, 9) β 11 | |
public int max1020(int a, int b) { | |
if(a>=10 || a<=20){ | |
return a; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Given two temperatures, return true if one is less than 0 and the other is greater than 100. | |
//icyHot(120, -1) β true | |
//icyHot(-1, 120) β true | |
//icyHot(2, 120) β false | |
public boolean icyHot(int temp1, int temp2) { | |
if(temp1<0 && temp2>100 || temp2<0 && temp1>100 ){ | |
return true; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Warmup-1 | |
//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) β true | |
//monkeyTrouble(false, false) β true | |
//monkeyTrouble(true, false) β false | |
public boolean monkeyTrouble(boolean aSmile, boolean bSmile) { | |
if(aSmile==bSmile){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
try { | |
Scanner sc = new Scanner(new File(args[0])); | |
int n = Integer.parseInt(sc.next()); | |
for (int i = 0; i < n; i++) { | |
System.out.println(sc.next()); // TEST | |
} | |
} catch (FileNotFoundException e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Given two int values, return their sum. Unless the two values are the same, then return double their sum. | |
//sumDouble(1, 2) β 3 | |
//sumDouble(3, 2) β 5 | |
//sumDouble(2, 2) β 8 | |
public int sumDouble(int a, int b) { | |
if(a==b){ | |
return a+b; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Warmup-1 | |
//intMax | |
// intMax | |
// Given three int values, a b c, return the largest. | |
public int intMax(int a, int b, int c) { | |
int max=0; | |
if(a>b && a>c){ | |
return a; | |
} |