10 * @author osama 11 12 import java.io.*; 13 14 import java.util.*; 15 gex 16 import java.io.File; 17 public class LAB6 ex2 {

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Why I get this error check code please
25585
ex2
urce Packages
lab6 ex2
10
* @author osama
11
12 E import java.io.*;
LAB6_ex2.java
13
fname
14
import java.util.*;
Test Packages
15
<default package
16
import java.io.File;
Libraries
public class LAB6 ex2 {
17
JDK 1.8 (Default)
18
Test Libraries
19 E
EST121212
@param args the command line arguments
ethrows java.io.IOException
20
21
22
23 E
public static void main(String{] args)throws IOException
# TODO COde applicatien Iogic nere
T| variable declaration
24
25
26
String fname=new String():
28
29
Scanner inp=new Scanner(System.in);//Scanner object
30
31
Iname-args[0];//ReadEilaname frOM cmd-
32
33
while (fname==null) {U/ Elename net given in cm
Output
Debugger Console x LAB6_ex2 (run) ×
run
D Exception in thread "main" ava.lang.ArrayIndexOutOEBoundsERception:0
at labe ex2 LABE ex2 main(LABE_ex2.java:31}
C:Users\osama AppData Local NetBeans\Cache\8.2texecuter-snippets\zun.ml:53E Java returned: 1
BUILD FAILED (Eotal time 0 seconds)
a 5 Output
O Type here to search
1080-
FULL
HD
Transcribed Image Text:25585 ex2 urce Packages lab6 ex2 10 * @author osama 11 12 E import java.io.*; LAB6_ex2.java 13 fname 14 import java.util.*; Test Packages 15 <default package 16 import java.io.File; Libraries public class LAB6 ex2 { 17 JDK 1.8 (Default) 18 Test Libraries 19 E EST121212 @param args the command line arguments ethrows java.io.IOException 20 21 22 23 E public static void main(String{] args)throws IOException # TODO COde applicatien Iogic nere T| variable declaration 24 25 26 String fname=new String(): 28 29 Scanner inp=new Scanner(System.in);//Scanner object 30 31 Iname-args[0];//ReadEilaname frOM cmd- 32 33 while (fname==null) {U/ Elename net given in cm Output Debugger Console x LAB6_ex2 (run) × run D Exception in thread "main" ava.lang.ArrayIndexOutOEBoundsERception:0 at labe ex2 LABE ex2 main(LABE_ex2.java:31} C:Users\osama AppData Local NetBeans\Cache\8.2texecuter-snippets\zun.ml:53E Java returned: 1 BUILD FAILED (Eotal time 0 seconds) a 5 Output O Type here to search 1080- FULL HD
C: > Users > VAM > Desktop > Charlotte > TYCSLAB > DAA > O SEFile.java > SEFile > main(String[)
import java.io.*;
import java.util.*;
import java.io.File;
public class SEFile {
Run | Debug
public static void main(String[] args) throws IOException
{
// variable declaration
String fname=new String();
Scanner inp=new Scanner(System.in);//Scanner object
fname=args[0];//Read filename from cmd
2
4
5.
6.
8.
9
10
11
while(fname==null){//If filename not given in cmd
System.out.println("Enter filename:");
fname=inp.nextLine();//Get filename from user
12
13
}
File file = new File(fname); //Create java file object with given file
FileInputStream fileStream = new FileInputStream(file); //Create FileInputStream object
14
15
16
17
InputStreamReader input = new InputStreamReader(fileStream); //Create InputStreamReader object
18
BufferedReader reader = new BufferedReader(input); //BufferedReader object to read file
19
String line;
20
// Initializing counters
int Word = e;
21
22
23
int sentence = 0;
24
int character = 0;
25
26
// Reading line by line from the file until null is returned
27
while( (line = reader.readLine()) != nul1)
28
{
29
character+= line.length(); //Line length gives number of characters in line
30
// \\s+ is the space delimiter in java
String[] wordList = line.split("\\s+");
31
32
33
34
Word += wordList.length;
35
36
sentencet=1; //Each line read by bufferedreader
37
}
38
System.out.println("Number of characters in file:"+character);//Display character count
39
System.out.println("Number of words in file:"+Word);//Display word count
System.out.println("Number of lines in file:"+sentence);//Display line count
System.out.println("Average number of words per line in file:"+Word/sentence);//Display avg word per line
40
41
42
System.out.println("Average number of characters per word in file:"+character/Word);//Display avg character count per word
43
}
44
Transcribed Image Text:C: > Users > VAM > Desktop > Charlotte > TYCSLAB > DAA > O SEFile.java > SEFile > main(String[) import java.io.*; import java.util.*; import java.io.File; public class SEFile { Run | Debug public static void main(String[] args) throws IOException { // variable declaration String fname=new String(); Scanner inp=new Scanner(System.in);//Scanner object fname=args[0];//Read filename from cmd 2 4 5. 6. 8. 9 10 11 while(fname==null){//If filename not given in cmd System.out.println("Enter filename:"); fname=inp.nextLine();//Get filename from user 12 13 } File file = new File(fname); //Create java file object with given file FileInputStream fileStream = new FileInputStream(file); //Create FileInputStream object 14 15 16 17 InputStreamReader input = new InputStreamReader(fileStream); //Create InputStreamReader object 18 BufferedReader reader = new BufferedReader(input); //BufferedReader object to read file 19 String line; 20 // Initializing counters int Word = e; 21 22 23 int sentence = 0; 24 int character = 0; 25 26 // Reading line by line from the file until null is returned 27 while( (line = reader.readLine()) != nul1) 28 { 29 character+= line.length(); //Line length gives number of characters in line 30 // \\s+ is the space delimiter in java String[] wordList = line.split("\\s+"); 31 32 33 34 Word += wordList.length; 35 36 sentencet=1; //Each line read by bufferedreader 37 } 38 System.out.println("Number of characters in file:"+character);//Display character count 39 System.out.println("Number of words in file:"+Word);//Display word count System.out.println("Number of lines in file:"+sentence);//Display line count System.out.println("Average number of words per line in file:"+Word/sentence);//Display avg word per line 40 41 42 System.out.println("Average number of characters per word in file:"+character/Word);//Display avg character count per word 43 } 44
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY