This file contains 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 int[] getColumn(int[][] arr2D, int c) { | |
int[] out = new int[arr2D.length]; | |
for (int r=0; r<arr2D.length; r++) | |
out[r] = arr2D[r][c]; | |
return out; | |
} |
This file contains 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 double runSimulation(int num) { | |
int good = 0; | |
for (int i=0; i<num; i++) | |
if (simulate()) | |
good++; | |
return (double)good / num; | |
} |
This file contains 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 class CodeWordChecker implements StringChecker { | |
private int min; | |
private int max; | |
private String no; | |
public CodeWordChecker(int mi, int ma, String n) { | |
min = mi; | |
max = ma; | |
no = n; | |
} |
This file contains 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 class GrayImage { | |
public static final int BLACK = 0; | |
public static final int WHITE = 255; | |
private int[][] pixelValues; | |
public int countWhitePixels() { | |
// Part A | |
} | |
public void processImage() { | |
// Part B | |
} |
This file contains 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 class Robot { | |
private int[] hall; | |
private int pos; | |
private boolean facingRight; | |
public boolean forwardMoveBlocked() { // part A } | |
private void move() { // part B } | |
public int clearHall() { // part C } | |
private boolean hallIsClear() { | |
// implementation not shown |
This file contains 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 class Cat extends Pet { | |
public Cat(String name) { | |
super(name); | |
} | |
public String speak() { | |
return "meow"; | |
} | |
} |
This file contains 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 int numWordsOfLength( int len ) { | |
int cnt = 0; | |
for (Object w: myList) { | |
String s = (String)w; | |
if (s.length() == len) { | |
cnt++; | |
} | |
} | |
return cnt; | |
This file contains 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 Digits( int num ) { | |
digitList = new ArrayList<>(); | |
int n = num; | |
do { | |
digitList.add(0, n % 10); | |
n /= 10; | |
} while (n > 0); | |
} |
This file contains 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 class MultPractice implements StudyPractice { | |
private int numOne; | |
private int numTwo; | |
public MultPractice(int a, int b) { | |
numOne = a; | |
numTwo = b; | |
} | |
This file contains 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
String[] wordArray = {"wheels", "on", "the", "bus"}; | |
RandomStringChooser sChooser = new RandomStringChooser(wordArray); | |
for (int k = 0; k < 6; k++) { | |
System.out.print(sChooser.getNext() + " "); | |
} | |
// Possible output | |
// bus the wheels on NONE NONE |
OlderNewer