2015 FRQ
2015 FRQ
//part A
public static int arraySum(int[] arr)
{
int sum = 0;
for(int n : arr)
sum += n;
return sum;
}
//part B
public static int[] rowSums(int[][] arr2D)
{
int[] sums = new int[arr2D.length];
for(int i = 0; i < sums.length; i++)
{
sums[i] = arraySum(arr2D[i]);
}
return sums;
}
//part C
public static boolean isDiverse(int[][] arr2D)
{
int[] sums = rowSums(arr2D);
for(int i = 0; i < sums.length; i++)
for(int j = i+1; j < sums.length; j++)
if(sums[i] == sums[j])
return false;
return true;
}
public class HiddenWord
{
private String hidden;
public HiddenWord(String h)
{
hidden = h;
}
public String getHint(String hint)
{
String r = "";
for(int i = 0; i < hint.length(); i++)
{
if(hint.charAt(i) == hidden.charAt(i))
r += ""+hint.charAt(i);
else if(hidden.indexOf(hint.charAt(i)) > -1)
r += "+";
else
r += "*";
}
return r;
}
}
public class IntByReference {
private int value;
public IntByReference(Integer value) {
this.value = value;
}
public String toString() {
return (String.format("%d", this.value));
}
public void swapToLowHighOrder(IntByReference i) {
if (this.value > i.value) {
int tmp = this.value;
this.value = i.value;
i.value = tmp;
}
}
public static void swapper(int n0, int n1) {
IntByReference a = new IntByReference(n0);
IntByReference b = new IntByReference(n1);
System.out.println("Before: " + a + " " + b);
a.swapToLowHighOrder(b); // conditionally build swap method to change values of a, b
System.out.println("After: " + a + " " + b);
System.out.println();
}
public static void main(String[] ags) {
IntByReference.swapper(21, 16);
IntByReference.swapper(16, 21);
IntByReference.swapper(16, -1);
}
}
IntByReference.main(null);