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){
}
}
About Question enthuware.ocajp.i.v7.2.1071 :
Moderator: admin
-
- Posts: 2
- Joined: Wed Apr 16, 2014 4:47 am
- Contact:
-
- Posts: 12
- Joined: Tue Aug 05, 2014 2:47 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1071 :
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){
}
}
-
- Posts: 2
- Joined: Wed Apr 16, 2014 4:47 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1071 :
I see. thanks
Who is online
Users browsing this forum: Google [Bot] and 34 guests