This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what's the meaning of " a[j]++?, thanks

 
Tu Ran
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A {
static void method(int [] a){
int j=1;
a[j]++; //I can't understand this sentence?
}
public static void main(String args[]) {
int [] b=new int[5];
method(b);
System.out.println(b[1]);
}
}
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a[j]++ basically increments the value of the j-th element in array a.
Here, we create a new int array of length 5. Then we pass the array to method(). Within method(), we increment its 1st element from 0 to 1 and then finally in main() we print that first element which is now 1.
 
Tu Ran
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks my friends--Valentin Crettaz
I see~~
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic