• 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

for loop error

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.*;
class SplitTest {
public static void main(String[] args) {
String[] tokens = args[0].split(args[1]);
System.out.println("count " + tokens.length);
for(String s : tokens)
System.out.println(">" + s + "<");
}
}
I am getting compilation error in the for statement .
Could any body explain how this for loop works.
 
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
chandu
I have executed your program ,i am not getting any error
could you share that error .

And i have some probelm with the split method have you understood that one.
Please see

PROBLEM IN SPLIT METHDOD in the main page
 
chandra reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Anil,
i understood the split method , example abc5xya6adf9764 suppose we are spliting based on digit then it will split in to abc,xya and adf .so it also doing same it is not considering lost 764 , it consider if any nondigits only.

coming to my doubt am not understanding the the new format of for loop .
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you compiling it with Java 5.0?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And please read our JavaRanch Naming Policy and change your display name to comply with it.
Thanks
 
anil kumar
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
chandu

What are you not able to understand?

The for loop is like this
if it is an int array the loop variable should be int like
int[] a={1,2,3,4};
for(int i:a)
System.out.println(i);

here i contains the value of a according to the index
Thanks
[ April 13, 2007: Message edited by: anil kumar ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic