what’s wrong? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

what’s wrong?

import java.util.Scanner; public class Program { public static void main(String[] args) { int x=3; int y=4; int z=4; if (x>2) if(y>2) z=x+y; System.out.println("z is"+z); } } else System.out.println("x is" + x);

7th Oct 2020, 8:15 PM
Blue Monster
Blue Monster - avatar
3 Answers
+ 2
You have problem with the curly brakets your else code is outside the class also try using curly brakets when you have more than one statement in if and else I guess that what you are trying to do import java.util.Scanner; public class Program { public static void main(String[] args) { int x=3; int y=4; int z=4; if (x>2) if(y>2){ z=x+y; System.out.println("z is "+z); } else System.out.println("x is " + x); } }
7th Oct 2020, 8:21 PM
Ruba Kh
Ruba Kh - avatar
+ 1
wooow thank you i was trying to solve it for half hour thank you so much
7th Oct 2020, 8:31 PM
Blue Monster
Blue Monster - avatar
0
You are welcome 👍🏼
7th Oct 2020, 8:31 PM
Ruba Kh
Ruba Kh - avatar