Brian Kenney

Greenhorn
+ Follow
since Mar 22, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brian Kenney

Ahh!! Thank you. I now understand.
6 years ago
I think its 3 because of the 3 occurrences of the 100...but I am thinking the code is just counting the index locations to get 4? Based on the conditional?
6 years ago
Ok...I am having some trouble wrapping my head around the answer to a problem. Here it is:

// returns index of first occurrence of valid arr
// after position start;
// returns arr.length if val is not found
public int findNext(int[] arr, int val, int start)
{
int pos = start + 1;

while ((pos < arr.length) && (arr[pos] != val))
pos++;

return pos;
}

int[] arr = {11, 22, 100, 33, 100, 11, 44, 100};

System.out.println(findNext(arr, 100, 2));

The execution of the code results in the value 4 being printed. The way I see it, the result should be 3 right?

Also, why does the code not work if I change the condition to (arr[pos] != val) && (pos < arr.length)

Thanks for the help!!
6 years ago
System.out.println(0x47 ^ 0xA3);

What does this do? My initial reaction was exponent, but that can't be it. I compiled and ran...answer: 228

Does it convert to decimal from hex?

Thanks!
6 years ago
ok...I get how the result is 16. So, how do you know how many times it executes?
7 years ago
Recursion explanation...I cannot wrap my head around the explanation. Can someone please help? I know the answer is 16, I just don't know why. I understand if it is only one recurusive call, but two? HELP!

import java.util.*;
import acm.program.*;

public class Recursion extends ConsoleProgram{

public int recur(int n)
{
if (n<=10)
return n * 2;
else
return recur(recur(n / 3));
}

public void run(){

println(recur(27));

}
}
7 years ago