The Artima Developer Community
Sponsored Link

Java Answers Forum
looping

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
ben

Posts: 57
Nickname: loftty
Registered: Oct, 2002

looping Posted: Nov 20, 2002 2:12 AM
Reply to this message Reply
Advertisement
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
import java.io.*;
import java.util.*;
import java.lang.*;
import java.util.StringTokenizer.*;

public class RT2 {


public static void main(String[] args) {
String cT = null;
String lT = null;
try {
Vector v = new Vector(100);
FileReader file = new FileReader("Work.csv");
BufferedReader buff = new BufferedReader(file);
String line = buff.readLine();
StringTokenizer s = null;
boolean eof = false;
while (!eof){
s = new StringTokenizer(line.trim(),",",true);
while (s.hasMoreTokens()) {
cT = s.nextToken();
if (cT.equals(",") && lT.equals(",")){
v.add("");
}
else{
if (!cT.equals(",")) {
v.add(cT);
}
}
lT = cT;

}
line = buff.readLine();
if (line == null)
eof = true;
}
Enumeration e = v.elements();
Object o;
for(int i = 0;e.hasMoreElements();i++) {
o = e.nextElement();
if (i%10 == 0){
System.out.println(o.toString());

}

}
buff.close();
}catch (FileNotFoundException fe) {
System.out.println("Error - - " + fe.toString());
}catch (NumberFormatException ne) {
System.out.println("Error - - " + ne.toString());
} catch (IOException e) {
System.out.println("Error - - " + e.toString());

}
}
}

Topic: Making  a Menu System out of JFrame Previous Topic   Next Topic Topic: hey i understand the array concept but struggling

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use