• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

operator's

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class vote
{
static int i=0;
static int arr[];
public static void lap()
{
int f=0;
arr=new int[5];
arr[i]=2;
arr[i++];
for(int p=0;p<arr.length;p++)>
{
System.out.println(arr[p]);
}
}
public static void main(String[]args)
{
vote v=new vote();
v.lap();
}
}
I am getting an error at line 10, invalid expression.Please correct it and tell me, why this error is coming.If i change that line with the following line.
arr[i]++; then i don't get any error.
 
Ranch Hand
Posts: 400
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first : your for loop is error,
second : it is very obvious arr[i++]; is not an expression, it is same if you write arr[i], or arr[2], or "i", what ever...there is no expression in there.
but if you write arr[i]++, there is an expression, because :
arr[i]++ is equal with : arr[i] = arr[i] + 1;
hope this help
stevie
 
Onion rings are vegetable donuts. Taste this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic