> I'm struggling in Java Programming. Could somebody break these down for me?

I'm struggling in Java Programming. Could somebody break these down for me?

Posted at: 2014-12-18 
I don't understand the questions. (Also, this assignment doesn't weight on my grade. I just need to get the content down.)



What is it that you don't understand about #1? Is it the Math.random() function? The multiplication by 10? The conversion to int? All of the above?

Programming is not a flash-card-and-regurgitate subject. There are things you need to learn and remember, though.

For #1, Math.random() returns a double x in the range 0.0 <= x < 1.0. When you see something like that and you aren't familiar with the method being used, go DIRECTLY to the docs. (Do not pass Go, etc.)

http://docs.oracle.com/javase/7/docs/api...

Scroll down to find the random() method.

Multiplying by 10 makes:

0.0 <= 10*x < 10.0

If you ever asked "When am I going to use this?" in Algebra 1, you now have an answer.

After integer conversion:

0 <= (int)(10*x) < 10 .... means that the result is an int from 0 to 9 inclusive.

You can answer all of these questions yourself, if you're not hopeless. For #2, go to the book and read the description of each of those operators so that you know what they do. There's only two possible inputs for a boolean x: true or false. Find out which of those operations will give a false result when x is true and also when x is false. Since true && true == true, then && is not an answer.

For #3, you need to read (and reread, if needed) about the switch statement. This is something you must know. If your book doesn't help, try this:

http://docs.oracle.com/javase/tutorial/j...

For #4, again you must know what the different operations are. You can look them up to understand someone else's code, but you can't very well use them in your own code without knowing what they are and what they're good for.

When you analyze a complex expression, add parentheses to make the order of operations crystal clear. Then work from the innermost parentheses outward--substituting values and computing results. I'll do the last one as an example:

y || !y ? x : 5 ..... groups as:

(y || (!y)) ? x : 5 .... the ?: "triple operator" is a single operation

Now plug values:

(false || (!false)) ? 10 : 5

(false || true) ? 10 : 5

true ? 10 : 5

10

So, no, you do not get 5 out of that expression. Use the same method on the others.

Additional questions:



I don't understand the questions. (Also, this assignment doesn't weight on my grade. I just need to get the content down.)