please anyone clarify that why this code give "No Output" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

please anyone clarify that why this code give "No Output"

https://code.sololearn.com/c1Gsu0Tmv783/?ref=app

24th Jul 2020, 6:36 AM
kumar_bittu
kumar_bittu - avatar
4 Answers
+ 4
Hey kumar bittu , just you need to keep this statement System.out.println("biggest number is " + reasult); out of else block {} , you kept this statement in else block as condition a>b is true it enters into if block rather than else block so that's why there's no output Code is here: public class Program { public static void main(String[] args) { int a=8; int b=5; int c=12; int reasult= 0; if (a>b) { if (a>c) { reasult=a; } else{ reasult=c; } } else{ if (b>c){ reasult=b; } else { reasult=c; } } System.out.println("biggest number is " + reasult); } }
24th Jul 2020, 6:43 AM
Nikhil Maroju
Nikhil Maroju - avatar
+ 1
As a is bigger then b the first condition evaluates to true and you didn't put any print statement in it or at least out of all conditions.
24th Jul 2020, 6:41 AM
Eliya Ben Baruch
Eliya Ben Baruch - avatar
+ 1
But when first condition is true it goes nested inner if block, if inner if block is not true than code needs to exicute nested else and print c as a reasult...
24th Jul 2020, 6:51 AM
kumar_bittu
kumar_bittu - avatar
+ 1
kumar bittu Write Print Statement out of first if statement else because if statement evaluates true so your print statement which is inside else doesn't runs Try this : https://code.sololearn.com/cL80PtWftlId/?ref=app
24th Jul 2020, 6:59 AM
Akash
Akash - avatar