Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[JAVA] Please find error. This isn't working. ---------------------------------------------------------------------------------------------- import java.io.*; import java.util.*; public class CountWordsFile { @SuppressWarnings(resource) public static void main(String[] args){ String javaprogramming =

[JAVA]

Please find error. This isn't working.

----------------------------------------------------------------------------------------------

import java.io.*;

import java.util.*;

public class CountWordsFile {

@SuppressWarnings("resource")

public static void main(String[] args){

String javaprogramming = args[0];

TreeMapTreeMap=new TreeMap();

try{

Scanner input = new Scanner(new File("testing.txt"));

while (input.hasNext()){

String line=input.nextLine();

String[]words=line.split("[ @!~{}\\[\\]$#^&* \t .,;?'\")(] "); for (int i=0;i

if (words[i].trim().length () >0 && words[i].trim().matches("[A-Z|a-z]+")){

String key =words[i].toLowerCase();

if (TreeMap.get(key)!=null){

int count =TreeMap.get(key);

count++;

TreeMap.put(key,count);

}

else{

TreeMap.put(key, 1);

}

}

}

}

}

catch (Exception ex){

ex.printStackTrace();

}

Set>entrySet=TreeMap.entrySet();

System.out.print(" Total words in the file:");

for (Map.Entryentry: entrySet) System.out.println(entry.getValue()+"\t" +entry.getKey());

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

Students also viewed these Databases questions

Question

1. What is a security? LOP8

Answered: 1 week ago

Question

2. What are the two main functions of the financial system? LOP8

Answered: 1 week ago