Login Register


[EASY] Programming Challenge filter_list
Author
Message
RE: [EASY] Programming Challenge #15
Here's my solution in Java:

Spoiler:
Code:
public static void main(String[] args) {        int lines = 0; //Number of lines in the text file        int chars = 0; //Number of characters in the text file        List<String> text; //Stores all the items from the text file                Scanner textFile = new Scanner(System.in);//Scanner Object                System.out.println("Path to To Text File: ");        String path = textFile.nextLine();//Read User input        File file = new File(path);                if(file.isFile()) { //Check if file exists            try(BufferedReader read = new BufferedReader(new FileReader(path))) {                                text = read.lines().collect(Collectors.toList());//Convert Stream to List                chars = text.stream().map((items) -> (items.replaceAll("\\s+", "")).length()).reduce(chars, Integer::sum);//Reduce to Chars and count                                //Print Results                System.out.println("Total Lines: " + text.size());                System.out.println("Total Characters: " + chars);                            } catch (Exception e) {                System.out.println(e);            }        } else {            System.out.println("File not found!");        }    }
My Blog: http://www.procurity.wordpress.com
Donations: 1HLjiSbnWMpeQU46eUVCrYdbkrtduX7snG

Reply





Messages In This Thread
[EASY] Programming Challenge - by Dong - 09-14-2013, 05:48 PM
RE: [EASY] Programming Challenge - by Dong - 09-14-2013, 07:21 PM
RE: [EASY] Programming Challenge - by Oni - 09-14-2013, 07:15 PM
RE: [EASY] Programming Challenge - by Oni - 09-14-2013, 07:21 PM
RE: [EASY] Programming Challenge - by Oni - 09-14-2013, 07:25 PM
RE: [EASY] Programming Challenge - by w00t - 09-14-2013, 07:26 PM
RE: [EASY] Programming Challenge - by Dong - 09-14-2013, 07:43 PM
RE: [EASY] Programming Challenge - by meow - 07-25-2016, 06:49 PM
RE: [EASY] Programming Challenge - by Wildfire - 07-26-2016, 02:18 AM
RE: [EASY] Programming Challenge - by meow - 07-27-2016, 02:31 AM
RE: [EASY] Programming Challenge - by Ex094 - 07-27-2016, 05:46 AM



Users browsing this thread: 1 Guest(s)