**MEDAL + FAN** Please check my Java Programming answers. If they're wrong, please help me figure out the answer (if you can/have the time). I want to learn how do these on my own.
This looks like a test.
@e.mccormick Nope. It's worth 0% of my grade, and the assignment is here to help us see where we stand in the class so far. However, I've searched the books AND contacted my teacher several times and I still don't understand the content. That's why I came to OS to see if someone could help me.
Well, one thing you can do with this sort of thing is try the code. ``` // Test program class TestProgram { public static void main(String args[]) { print(int[]{32, 15, 5, 9}); } public static void print(int[] p){ for (int x : p) System.out.println(x); } } ``` gets "Syntax error on token(s), misplaced construct(s)" but ``` // Test program class TestProgram { public static void main(String args[]) { print(new int[]{32, 15, 5, 9}); } public static void print(int[] p){ for (int x : p) System.out.println(x); } } ``` works. For #2, they key is the word "reference." Thought it is misued and the author of the question must have a c/c++ background. Also, none of those are a a very valid answer unless you goal is to know the memory address as an integer. The one you selected might do that... the first one has an invalid < in front, but is otherwise correct. #3, they do not use the *, &, and -> pointers in Java. You want it as an array. #4, a the top of the Arrays documentation you will see that it has several methods listed for binarySearch. This is called an overload. It will use the proper one based on what is passed to it. https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.html You may notice it does more than ints... so if you scroll down the page, you can find things like: binarySearch public static int binarySearch(long[] a, long key) Searches the specified array of longs for the specified value using the binary search algorithm. The array must be sorted (as by the sort(long[]) method) prior to making this call. If it is not sorted, the results are undefined. If the array contains multiple elements with the specified value, there is no guarantee which one will be found. That should help. #5 you have correct, but I want to point out that if you scroll down that Arrays page you can also see things that talk about Equals and what it means.
Thanks! I figured it out already, but the information you sent me will help me out for future (graded) assignments :)
Oh, and understanding the Java documentation made by JavaDoc is an exercize in making you brain bleed until you are suddenly there. It is like this cryptic, confusing stuff until you have learned enough Java to go, "OH, that is what it means!" So horrific for learning but OK after you have learned.
Join our real-time social learning platform and learn together with your friends!