• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

looping

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello i hope someone can help me i have this code which is looping though the vector and picking out the first word of a line then it loops though and picks out every 10th word so i get the first word of each line. but i want another loop so i can print out the second word of each line and the third and so on.
any suggestions would be grateful
thanks ben

(edited by Cindy to format code . . . pleeeeeeease try to do it yourself next time)
[ November 20, 2002: Message edited by: Cindy Glass ]
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code would be different (simpler) if you knew for sure each line would contain the same number of words. Is that the case? What you might do is read the file line by line and token by token, and push each word into a List of Lists (a 2-dimensional ArrayList), and then you would have random access to any arbitrary word of any arbitrary line. You'd basically have 2 nested while loops, 1 for the BufferedReader.readLine(), and one for StringTokenizer.hasMoreTakens().
 
Evil is afoot. But this tiny ad is just an ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic