SlideShare a Scribd company logo
1 of 2
Download to read offline
Can some one redo this code without the try-catch and an alternative to using Entry when
printing the treemap
package part2;
import java.io.*;
import java.util.Map.Entry;
import java.util.*;
public class frequencyOfWords {
public static void main(String[] args) {
long totalTime = 0;
long startTime = System.nanoTime();
TreeMap map = new TreeMap<>();
for(int i=1; i <= 77; i++){
startTime = System.nanoTime();
Scanner sc = new Scanner(System.in);
File file = new File("c:/Users/tvazq/IdeaProjects/hw2/resources/" + i +".okpuncs");
Scanner reader;
String line = "";
try {
reader = new Scanner(file);
while(reader.hasNextLine()){
line = reader.nextLine();
String words[] = line.split(" ");
for(String s : words){
if(map.containsKey(s)){
map.put(s, map.get(s)+1);
}else{
map.put(s, 1);
}
}
}
} catch (FileNotFoundException e) {
System.out.println("file not found");
}
sc.close();
totalTime+= (System.nanoTime()-startTime);
}
System.out.printf("%-20s%-20sn","Word","Frequency");
for(Entry entry : map.entrySet()) //printing map
System.out.printf("%-20s%-20dn",entry.getKey(),entry.getValue());
System.out.println("Total time took : " + totalTime);
}
}

More Related Content

Similar to Can some one redo this code without the try-catch and an alternative.pdf

От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовYandex
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab FileKandarp Tiwari
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docxKatecate1
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Flink Forward
 
please help finish sorting methods- import java-util-Arrays- import ja.pdf
please help finish sorting methods- import java-util-Arrays- import ja.pdfplease help finish sorting methods- import java-util-Arrays- import ja.pdf
please help finish sorting methods- import java-util-Arrays- import ja.pdfanfenterprises
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовYandex
 
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdfimport java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdfadhityalapcare
 
Comments added... import java.io.File; import java.io.FileNotF.pdf
Comments added... import java.io.File; import java.io.FileNotF.pdfComments added... import java.io.File; import java.io.FileNotF.pdf
Comments added... import java.io.File; import java.io.FileNotF.pdfanwarfoot
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1Ankit Gupta
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxvishal choudhary
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIjagriti srivastava
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoinknight1128
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diplomamustkeem khan
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming AssignmentCoding Assignment Help
 
Program Assignment Process ManagementObjective This program a.docx
Program Assignment  Process ManagementObjective This program a.docxProgram Assignment  Process ManagementObjective This program a.docx
Program Assignment Process ManagementObjective This program a.docxwkyra78
 

Similar to Can some one redo this code without the try-catch and an alternative.pdf (20)

От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей Родионов
 
Java final lab
Java final labJava final lab
Java final lab
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced Apache Flink Training: DataStream API Part 2 Advanced
Apache Flink Training: DataStream API Part 2 Advanced
 
please help finish sorting methods- import java-util-Arrays- import ja.pdf
please help finish sorting methods- import java-util-Arrays- import ja.pdfplease help finish sorting methods- import java-util-Arrays- import ja.pdf
please help finish sorting methods- import java-util-Arrays- import ja.pdf
 
От Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей РодионовОт Java Threads к лямбдам, Андрей Родионов
От Java Threads к лямбдам, Андрей Родионов
 
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdfimport java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
import java-util-Arrays- import java-io-PrintWriter- import java-io-Fi.pdf
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
srgoc
srgocsrgoc
srgoc
 
ExtraFileIO.pptx
ExtraFileIO.pptxExtraFileIO.pptx
ExtraFileIO.pptx
 
Comments added... import java.io.File; import java.io.FileNotF.pdf
Comments added... import java.io.File; import java.io.FileNotF.pdfComments added... import java.io.File; import java.io.FileNotF.pdf
Comments added... import java.io.File; import java.io.FileNotF.pdf
 
java program assigment -1
java program assigment -1java program assigment -1
java program assigment -1
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptx
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 
Jdk 7 4-forkjoin
Jdk 7 4-forkjoinJdk 7 4-forkjoin
Jdk 7 4-forkjoin
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
JAVA Question : Programming Assignment
JAVA Question : Programming AssignmentJAVA Question : Programming Assignment
JAVA Question : Programming Assignment
 
Program Assignment Process ManagementObjective This program a.docx
Program Assignment  Process ManagementObjective This program a.docxProgram Assignment  Process ManagementObjective This program a.docx
Program Assignment Process ManagementObjective This program a.docx
 

More from MAYANKBANSAL1981

Business management 1. True or False Diversification is when compa.pdf
Business management  1. True or False Diversification is when compa.pdfBusiness management  1. True or False Diversification is when compa.pdf
Business management 1. True or False Diversification is when compa.pdfMAYANKBANSAL1981
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdfMAYANKBANSAL1981
 
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfMAYANKBANSAL1981
 
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdfCase Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdfMAYANKBANSAL1981
 
Banks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdfBanks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdfMAYANKBANSAL1981
 
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdfASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdfMAYANKBANSAL1981
 
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdfA. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdfMAYANKBANSAL1981
 
About your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdfAbout your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdfMAYANKBANSAL1981
 
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdfAbout your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdfMAYANKBANSAL1981
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfMAYANKBANSAL1981
 
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdfAbout your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdfMAYANKBANSAL1981
 
About your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdfAbout your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdfMAYANKBANSAL1981
 
Answer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdfAnswer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdfMAYANKBANSAL1981
 
Advanced level school Python programming. Need helps. Thank.pdf
Advanced level school Python programming.  Need helps. Thank.pdfAdvanced level school Python programming.  Need helps. Thank.pdf
Advanced level school Python programming. Need helps. Thank.pdfMAYANKBANSAL1981
 

More from MAYANKBANSAL1981 (14)

Business management 1. True or False Diversification is when compa.pdf
Business management  1. True or False Diversification is when compa.pdfBusiness management  1. True or False Diversification is when compa.pdf
Business management 1. True or False Diversification is when compa.pdf
 
Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdfChange to oop formatimport java.util.Scanner;import java.io.;.pdf
Change to oop formatimport java.util.Scanner;import java.io.;.pdf
 
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdfCase Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
Case Project 2-1 Advance PreparationsThe IT managers from Chicago.pdf
 
Banks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdfBanks are singled out for special attention in the financial sys.pdf
Banks are singled out for special attention in the financial sys.pdf
 
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdfASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
ASSETS LIABILITIES Cash $10,000 Accounts payable $12,000 Accounts re.pdf
 
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdfA. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
A. Monitoring Internet Endpoints and Bandwidth Consumption1. NetFl.pdf
 
About your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdfAbout your clientName Samantha BensonAge 54Marital status .pdf
About your clientName Samantha BensonAge 54Marital status .pdf
 
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdfAbout your clientName Samantha Benson Age 54 Marital status Ma.pdf
About your clientName Samantha Benson Age 54 Marital status Ma.pdf
 
a) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdfa) Complete both insert and delete methods. If it works correctly 10.pdf
a) Complete both insert and delete methods. If it works correctly 10.pdf
 
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdfAbout your client Name Samantha Benson Age 54 Marital status Ma.pdf
About your client Name Samantha Benson Age 54 Marital status Ma.pdf
 
About your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdfAbout your client Name Samantha BensonAge 54Marital status.pdf
About your client Name Samantha BensonAge 54Marital status.pdf
 
Answer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdfAnswer the following prompts 1The InstantRide Management team foun.pdf
Answer the following prompts 1The InstantRide Management team foun.pdf
 
Advanced level school Python programming. Need helps. Thank.pdf
Advanced level school Python programming.  Need helps. Thank.pdfAdvanced level school Python programming.  Need helps. Thank.pdf
Advanced level school Python programming. Need helps. Thank.pdf
 

Recently uploaded

UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfNirmal Dwivedi
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfKartik Tiwari
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17Celine George
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsPallavi Parmar
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxRugvedSathawane
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxCeline George
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonhttgc7rh9c
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code ExamplesPeter Brusilovsky
 

Recently uploaded (20)

UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdfDiuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
Diuretic, Hypoglycemic and Limit test of Heavy metals and Arsenic.-1.pdf
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Ernest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell TollsErnest Hemingway's For Whom the Bell Tolls
Ernest Hemingway's For Whom the Bell Tolls
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 

Can some one redo this code without the try-catch and an alternative.pdf

  • 1. Can some one redo this code without the try-catch and an alternative to using Entry when printing the treemap package part2; import java.io.*; import java.util.Map.Entry; import java.util.*; public class frequencyOfWords { public static void main(String[] args) { long totalTime = 0; long startTime = System.nanoTime(); TreeMap map = new TreeMap<>(); for(int i=1; i <= 77; i++){ startTime = System.nanoTime(); Scanner sc = new Scanner(System.in); File file = new File("c:/Users/tvazq/IdeaProjects/hw2/resources/" + i +".okpuncs"); Scanner reader; String line = ""; try { reader = new Scanner(file); while(reader.hasNextLine()){ line = reader.nextLine(); String words[] = line.split(" "); for(String s : words){ if(map.containsKey(s)){ map.put(s, map.get(s)+1); }else{ map.put(s, 1); } } } } catch (FileNotFoundException e) { System.out.println("file not found");
  • 2. } sc.close(); totalTime+= (System.nanoTime()-startTime); } System.out.printf("%-20s%-20sn","Word","Frequency"); for(Entry entry : map.entrySet()) //printing map System.out.printf("%-20s%-20dn",entry.getKey(),entry.getValue()); System.out.println("Total time took : " + totalTime); } }