java - Exercice with scan files -
i have print lines of file "text", how can that?
public static void main(string[] args) throws filenotfoundexception{ file f =new file("text.txt"); scanner scanner = new scanner(f); while(scanner.hasnextline()){ system.out.println(scanner.nextline()); } }
thank you.
here easy way keep track of line on , how tell if number or not. if indeed number, print it.
public static void main(string[] args) throws filenotfoundexception { file f = new file("text.txt"); scanner scanner = new scanner(f); int counter = 1; //this tell line on while(scanner.hasnextline()) { if (counter % 2 == 0) { //this checks if line number system.out.println(scanner.nextline()); } counter++; //this says looked @ 1 more line } }
Comments
Post a Comment