What is wrong with the following code? | Sololearn: Learn to code for FREE!
+ 6

What is wrong with the following code?

if(int j<=10); n=n+j;

12th Jan 2019, 1:53 PM
hunaysubhash chennu
hunaysubhash chennu - avatar
6 Answers
+ 7
● if(j <=10) n+=j; //n=n+j; //not necessary to use { } , if only 1 statement to execute if if() condition evaluates to true.
12th Jan 2019, 4:57 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 3
; means statement ended Should be { after if (...)
12th Jan 2019, 2:04 PM
Gordon
Gordon - avatar
+ 3
Well not sue what language you're talking about since you used a lot of tags but: Make sure to initialize the variables before using them for example in C#: int n = 0; int j = 10; if(j <= 10) { n += j; //this is the same as n = n + j; } You're not able to initialize the variable inside a statement like "if" you can however do it in a for loop and don't end the statement with a ";" you just have open and close a bracket; ruby: n = 0 j = 10 if j <= 10 n += j //same as n = n + j end java is like the C# example; If you're using any IDE it will tell you what's wrong. Hope this helps!
12th Jan 2019, 2:09 PM
Joery De Loose
Joery De Loose - avatar
+ 2
if condition contain the;
28th Jan 2019, 4:33 AM
sai krishna Kudipudi
sai krishna Kudipudi - avatar
0
class Chair { String colour; int price; Chair(String colour, int p) { this.colour = colour; price = p; } void showPicture() { System.out.println("Display Chair picture"); } } class ArmChair extends Chair { int number_of_legs; ArmChair(int number_of_legs) { this.number_of_legs = number_of_legs; } ArmChair(int number_of_legs, String colour, int price) { this.number_of_legs = number_of_legs; this.colour = colour; this.price = price; } void showPicture() { System.out.println("Display ArmChair picture"); } } class ChairExample { public static void main(String[] a) { ArmChair a1 = new ArmChair(5); Chair a2 = new ArmChair(4, "yellow", 100); a1.showPicture(); a2.showPicture(); } } what is wrong with the following code help
6th Jul 2021, 9:39 AM
Reeya Patel
Reeya Patel - avatar
0
What is wrong with the following code
5th Oct 2021, 1:16 AM
Yen Sison
Yen Sison - avatar