+ 6
What is wrong with the following code?
if(int j<=10); n=n+j;
7 Respuestas
+ 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.
+ 3
; means statement ended
Should be { after if (...)
+ 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!
+ 2
if condition contain the;
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
0
What is wrong with the following code