Last active
August 29, 2015 14:00
-
-
Save JorgeOlvera/11205512 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Scanner; | |
| import java.io.*; | |
| public class countingLines { | |
| public static void main(String [] args) { | |
| try { | |
| //Scans file | |
| Scanner input = new Scanner(System.in); | |
| Scanner file = new Scanner(new File(text2.txt)); | |
| //Divides into tokens for second part of output | |
| StringTokenizer muchToken = new StringTokenizer(text2.txt) | |
| int lineCounter = 1; | |
| int wordCounter = 1; | |
| while (file.nextLine() != null){ | |
| lineCounter = lineCounter + 1; | |
| } | |
| while (muchToken.hasMoreTokens){ | |
| wordCounter = wordCounter + 1; | |
| } | |
| } | |
| catch (NoSuchElementException e) { | |
| break; | |
| } | |
| //Prints counter values (minus 1 to make up for the extra "1" when initialized) | |
| System.out.println("Numer of lines is equal to" + lineCounter-1); | |
| System.out.println("Number of words and/or numbers is equal to" + wordCounter-1) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment