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


A voir également:

3 réponses

choubaka Messages postés 39442 Date d'inscription   Statut Modérateur Dernière intervention   2 105
 
Bonjour

Ne cherchez plus, voir ci-dessous

Almanach des corrections d'exercices Java Edition 2012
1
domxaline
 
répondez moi svp
0
hichammoad
 
c) conditional operator :

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