Page 1 of 1
About Question enthuware.ocajp.i.v7.2.1071 :
Posted: Mon Sep 29, 2014 9:37 am
by dragontbone
when i run this code, I get a compile time error on this line: System.out.println(b = c);
what am i doing wrong?
public class Primitive{
int a = 1;
int[] ia = new int[10];
int b = ia[a];
int c = b + a;
System.out.println(b = c);
public static void main(String [ ] args){
}
}
Re: About Question enthuware.ocajp.i.v7.2.1071 :
Posted: Mon Sep 29, 2014 9:49 am
by sasha32003
dragontbone wrote:when i run this code, I get a compile time error on this line: System.out.println(b = c);
what am i doing wrong?
public class Primitive{
int a = 1;
int[] ia = new int[10];
int b = ia[a];
int c = b + a;
System.out.println(b = c);
public static void main(String [ ] args){
}
}
Hi. You cannot do System.out.println(); there. Has to be in a method or a constructor.
Your code should look something like this:
Code: Select all
public class Primitive{
int a = 1;
int[] ia = new int[10];
int b = ia[a];
int c = b + a;
public Primitive(){
System.out.println(b = c);
}
public static void main(String [ ] args){
}
}
Re: About Question enthuware.ocajp.i.v7.2.1071 :
Posted: Mon Oct 06, 2014 10:02 am
by dragontbone
I see. thanks