Reputation: 3
Hey I have problem with this simple program:
package werd;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
public class Werd {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
BufferedReader in = new BufferedReader(
new InputStreamReader(new FileInputStream("ikso.txt"), "UTF-8"));
String line;
String[] tmp = null;
int slowa = 0;
int lines = 0;
while ((line = in.readLine())!= null){
lines++;
tmp = line.split("\\s");
System.out.println(line);
//System.out.println(line);
for(String s : tmp){
slowa++;
}
}
in.close();
System.out.println("Liczba wierszy to " +line+" a liczba slow w tekscie to " + slowa)
}
}
Problem is that the variable counting is not increasing. Moreover Netbeans telling me that variable limits is not used. I had glanced at similar questions as min on this page. Way of solving counting number of lines was similar to mine. I don't understand why it doesn't work... Thanks
Upvotes: 0
Views: 101
Reputation: 18861
From the code you provided it seems you're printing line
instead of lines
.
The counting code looks correct.
Upvotes: 1