+ 1
When is used the colon (:) in a java program?
https://code.sololearn.com/cg9CbQkAaTcW/?ref=app In the method getQuality she used a colon and a "?", and would like someone to explain this for me.
5 Respuestas
+ 4
It is a short if-else statement:
condition ? inCaseOfTrue : elseCase;
http://www.knaupes.net/java-short-if-else-ternary-operator/
+ 3
quality = (points>100)&&(g.clarity==0)?"the best":(points>80)&&(g.clarity<=3)?"very high":(points>50)&&(g.clarity<=5)?"good":(g.clarity<=7)?"average":(g.clarity>7)?"poor":"unclassified";
Full if else statement:
if(points > 0 && g.clarity == 0){
quality = "the best";
}else if(points > 80 && g.clarity <= 3){
quality = "very high";
}else if(points > 50 && g.clarity <= 5){
quality = "good";
}else if(g.clarity <= 7){
quality = "average";
}else if(g.clarity < 7){
quality = "poor";
}else{
quality = "unclassified";
}
+ 2
Rafael Barbeta Your welcome :)
+ 1
Right, thank you!!!
0
By the way,this code was made by 1Lory