Java:j'ai besoin votre correction

Résolu
domxaline -  
 hichammoad -
Bonjour,
bonjour
j'ai besoin votre correction sur ce énoncé:

*write a program that will read the value of x and evaluate the following function
{ 1 for x > 0
y = { 0 for x = 0
{ -1 for x < 0

using
a) nested if statements,
if(x>=0)
if(x>0)
y=1;
else
y=0;
else
y=-1;

b) else if statements,
If(x>0)
y=1;
Elseif (x=0)
y=0;
Else
y=-1

c) conditional operator ?....
y=(x !=0) ?((x<0) ?(-1) :(1)) :0

aidez moi svp

3 réponses

  1. hichammoad
     
    c) conditional operator :

    y=(x >0) ? 1 : (x<0?-1:(0)) ;
    0