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 {
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...
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fcba60b6d-1c6b-443d-b5ed-735d8179c024%2F9bf9ba74-c1d0-4b81-87ba-9d9bbbef17c4%2Ftny84cf_processed.jpeg&w=3840&q=75)
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fcba60b6d-1c6b-443d-b5ed-735d8179c024%2F9bf9ba74-c1d0-4b81-87ba-9d9bbbef17c4%2Fwwg5z7_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
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…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
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)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
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](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY