can't understand a java statement - please help

M

Moham12345

hi,
im converting a program and can't understand a statement please can
you help

this is the statement

double s_star = (s_star_raw > s0) ? s_star_raw : s0;

so ok.. .if

s_star_raw = 15
s0 = 3

what is s_star?

thank you for helping.
 
J

Jeff Higgins

Moham12345 said:
hi,
im converting a program and can't understand a statement please can
you help

this is the statement

double s_star = (s_star_raw > s0) ? s_star_raw : s0;

so ok.. .if

s_star_raw = 15
s0 = 3

what is s_star?

thank you for helping.

if s_star_raw is greater than s0 then s_star equals s_star_raw otherwise
s_star equals s0
 
T

Tom Hawtin

Jeff said:
if s_star_raw is greater than s0 then s_star equals s_star_raw otherwise
s_star equals s0

Or to put it more sensibly:

double sStar = Math.max(sStarRaw, s0);

Tom Hawtin
 
S

Sherm Pendley

Moham12345 said:
im converting a program and can't understand a statement please can
you help

this is the statement

double s_star = (s_star_raw > s0) ? s_star_raw : s0;

The expression "(test) ? true_value : false_value" evaluates to true_value
if test is true, or false_value if not.

In other words, the above is equivalent to this:

double s_star;
if (s_star_raw > s0) {
s_star = s_star_raw;
} else {
s_star = s0;
}

sherm--
 
I

Ian Shef

hi,
im converting a program and can't understand a statement please can
you help

this is the statement

double s_star = (s_star_raw > s0) ? s_star_raw : s0;

so ok.. .if

s_star_raw = 15
s0 = 3

what is s_star?

thank you for helping.

I could give you the answer, but then what would you learn? Here is a
clue.

The expression

a?b:c

provides a value of "b" if "a" is true, otherwise it provides a value of
"c".

(The double quotes I used are meant as separators and not as indicators of
a String).

This should be enough of a clue to figure it out. If not, then you had
better back up and study Java some more.

Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top