+ 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.

8th May 2019, 12:25 AM
Rafael Barbeta
5 Answers
+ 4
It is a short if-else statement: condition ? inCaseOfTrue : elseCase; http://www.knaupes.net/java-short-if-else-ternary-operator/
8th May 2019, 12:44 AM
Denise Roßberg
Denise Roßberg - avatar
+ 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"; }
8th May 2019, 1:06 AM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Rafael Barbeta Your welcome :)
8th May 2019, 8:47 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Right, thank you!!!
8th May 2019, 9:51 AM
Rafael Barbeta
0
By the way,this code was made by 1Lory
8th May 2019, 12:26 AM
Rafael Barbeta