SlideShare a Scribd company logo
Write code to: open and read from a file called numbers this file contains a comma-separated
list of numbers (example: 4, 5, 0, 3, 2, 1, 0, 7) count the number of "Os" in the file print the
result to a file called output (example: the file contained 2 zeros) Use exception handling to
handle the lO Exceptions. (Do not use "throws lO Exception")
Solution
import java.util.*;
import java.io.File;
import java.io.IOException;
public class ReadFile
{
public static void main(String[] args)
throws IOException
{
Scanner textfile = new Scanner(new File("Some_Numbers.txt"));
filereader(textfile);
}
static void filereader(Scanner textfile)
{
int i = 0;
int sum = 0;
while(i <= 19)
{
System.out.println(textfile.nextInt());
sum = sum + textfile.nextInt();
i++;
}
}
}

More Related Content

More from zakashjain

Can anyone explain the common steps and differences of virus synthes.pdf
Can anyone explain the common steps and differences of virus synthes.pdfCan anyone explain the common steps and differences of virus synthes.pdf
Can anyone explain the common steps and differences of virus synthes.pdf
zakashjain
 
B. Wildcat Plumbing Supply Inc. Do We Have Gender DifferencesWil.pdf
B. Wildcat Plumbing Supply Inc. Do We Have Gender DifferencesWil.pdfB. Wildcat Plumbing Supply Inc. Do We Have Gender DifferencesWil.pdf
B. Wildcat Plumbing Supply Inc. Do We Have Gender DifferencesWil.pdf
zakashjain
 
Answer and explain.•In an organism with a diploid chromosome numbe.pdf
Answer and explain.•In an organism with a diploid chromosome numbe.pdfAnswer and explain.•In an organism with a diploid chromosome numbe.pdf
Answer and explain.•In an organism with a diploid chromosome numbe.pdf
zakashjain
 
2) To study protein localization signals you engineered a yeast strai.pdf
2) To study protein localization signals you engineered a yeast strai.pdf2) To study protein localization signals you engineered a yeast strai.pdf
2) To study protein localization signals you engineered a yeast strai.pdf
zakashjain
 
42. The splanchnic nerves A) innervate the adrenal medulla B) are par.pdf
42. The splanchnic nerves A) innervate the adrenal medulla B) are par.pdf42. The splanchnic nerves A) innervate the adrenal medulla B) are par.pdf
42. The splanchnic nerves A) innervate the adrenal medulla B) are par.pdf
zakashjain
 
________ is NOT a common cause for maintenance insomnia. Stress Eat.pdf
________ is NOT a common cause for maintenance insomnia.  Stress  Eat.pdf________ is NOT a common cause for maintenance insomnia.  Stress  Eat.pdf
________ is NOT a common cause for maintenance insomnia. Stress Eat.pdf
zakashjain
 
Write a simple JavaScript program in which the user selects choices .pdf
Write a simple JavaScript program in which the user selects choices .pdfWrite a simple JavaScript program in which the user selects choices .pdf
Write a simple JavaScript program in which the user selects choices .pdf
zakashjain
 
Why does Staphylococcus probably cause more contamination than Pro Pe.pdf
Why does Staphylococcus probably cause more contamination than Pro Pe.pdfWhy does Staphylococcus probably cause more contamination than Pro Pe.pdf
Why does Staphylococcus probably cause more contamination than Pro Pe.pdf
zakashjain
 
Which is the correct formula for Interest Coverage RatioQuestion .pdf
Which is the correct formula for Interest Coverage RatioQuestion .pdfWhich is the correct formula for Interest Coverage RatioQuestion .pdf
Which is the correct formula for Interest Coverage RatioQuestion .pdf
zakashjain
 
Which of the following statements is TRUE for an organism that has a.pdf
Which of the following statements is TRUE for an organism that has a.pdfWhich of the following statements is TRUE for an organism that has a.pdf
Which of the following statements is TRUE for an organism that has a.pdf
zakashjain
 
what is a trans isomerSolutiontrans isomer is a form of geomet.pdf
what is a trans isomerSolutiontrans isomer is a form of geomet.pdfwhat is a trans isomerSolutiontrans isomer is a form of geomet.pdf
what is a trans isomerSolutiontrans isomer is a form of geomet.pdf
zakashjain
 
A) explain why infections occur frequently in patients with lymp.pdf
A) explain why infections occur frequently in patients with lymp.pdfA) explain why infections occur frequently in patients with lymp.pdf
A) explain why infections occur frequently in patients with lymp.pdf
zakashjain
 
What are the benefits and major problems of the fiscal policy and mo.pdf
What are the benefits and major problems of the fiscal policy and mo.pdfWhat are the benefits and major problems of the fiscal policy and mo.pdf
What are the benefits and major problems of the fiscal policy and mo.pdf
zakashjain
 
This is for my immunology course. I am struggling to understand this.pdf
This is for my immunology course. I am struggling to understand this.pdfThis is for my immunology course. I am struggling to understand this.pdf
This is for my immunology course. I am struggling to understand this.pdf
zakashjain
 
The superior portion of the sternum it the ____. glenoid fossa body.pdf
The superior portion of the sternum it the ____.  glenoid fossa  body.pdfThe superior portion of the sternum it the ____.  glenoid fossa  body.pdf
The superior portion of the sternum it the ____. glenoid fossa body.pdf
zakashjain
 
The half-life of a particular element is 410 days. What is its decay.pdf
The half-life of a particular element is 410 days. What is its decay.pdfThe half-life of a particular element is 410 days. What is its decay.pdf
The half-life of a particular element is 410 days. What is its decay.pdf
zakashjain
 
Suppose events A and B are mutually exclusive and at least one of th.pdf
Suppose events A and B are mutually exclusive and at least one of th.pdfSuppose events A and B are mutually exclusive and at least one of th.pdf
Suppose events A and B are mutually exclusive and at least one of th.pdf
zakashjain
 
Q1. Why are the birds discussed in this lab called Darwins finches.pdf
Q1. Why are the birds discussed in this lab called Darwins finches.pdfQ1. Why are the birds discussed in this lab called Darwins finches.pdf
Q1. Why are the birds discussed in this lab called Darwins finches.pdf
zakashjain
 
Preganglionic sympathetic neurons and postganglionic sympathetic neur.pdf
Preganglionic sympathetic neurons and postganglionic sympathetic neur.pdfPreganglionic sympathetic neurons and postganglionic sympathetic neur.pdf
Preganglionic sympathetic neurons and postganglionic sympathetic neur.pdf
zakashjain
 
Please answer this in a simple way and short. thank youQ What are.pdf
Please answer this in a simple way and short. thank youQ What are.pdfPlease answer this in a simple way and short. thank youQ What are.pdf
Please answer this in a simple way and short. thank youQ What are.pdf
zakashjain
 

More from zakashjain (20)

Can anyone explain the common steps and differences of virus synthes.pdf
Can anyone explain the common steps and differences of virus synthes.pdfCan anyone explain the common steps and differences of virus synthes.pdf
Can anyone explain the common steps and differences of virus synthes.pdf
 
B. Wildcat Plumbing Supply Inc. Do We Have Gender DifferencesWil.pdf
B. Wildcat Plumbing Supply Inc. Do We Have Gender DifferencesWil.pdfB. Wildcat Plumbing Supply Inc. Do We Have Gender DifferencesWil.pdf
B. Wildcat Plumbing Supply Inc. Do We Have Gender DifferencesWil.pdf
 
Answer and explain.•In an organism with a diploid chromosome numbe.pdf
Answer and explain.•In an organism with a diploid chromosome numbe.pdfAnswer and explain.•In an organism with a diploid chromosome numbe.pdf
Answer and explain.•In an organism with a diploid chromosome numbe.pdf
 
2) To study protein localization signals you engineered a yeast strai.pdf
2) To study protein localization signals you engineered a yeast strai.pdf2) To study protein localization signals you engineered a yeast strai.pdf
2) To study protein localization signals you engineered a yeast strai.pdf
 
42. The splanchnic nerves A) innervate the adrenal medulla B) are par.pdf
42. The splanchnic nerves A) innervate the adrenal medulla B) are par.pdf42. The splanchnic nerves A) innervate the adrenal medulla B) are par.pdf
42. The splanchnic nerves A) innervate the adrenal medulla B) are par.pdf
 
________ is NOT a common cause for maintenance insomnia. Stress Eat.pdf
________ is NOT a common cause for maintenance insomnia.  Stress  Eat.pdf________ is NOT a common cause for maintenance insomnia.  Stress  Eat.pdf
________ is NOT a common cause for maintenance insomnia. Stress Eat.pdf
 
Write a simple JavaScript program in which the user selects choices .pdf
Write a simple JavaScript program in which the user selects choices .pdfWrite a simple JavaScript program in which the user selects choices .pdf
Write a simple JavaScript program in which the user selects choices .pdf
 
Why does Staphylococcus probably cause more contamination than Pro Pe.pdf
Why does Staphylococcus probably cause more contamination than Pro Pe.pdfWhy does Staphylococcus probably cause more contamination than Pro Pe.pdf
Why does Staphylococcus probably cause more contamination than Pro Pe.pdf
 
Which is the correct formula for Interest Coverage RatioQuestion .pdf
Which is the correct formula for Interest Coverage RatioQuestion .pdfWhich is the correct formula for Interest Coverage RatioQuestion .pdf
Which is the correct formula for Interest Coverage RatioQuestion .pdf
 
Which of the following statements is TRUE for an organism that has a.pdf
Which of the following statements is TRUE for an organism that has a.pdfWhich of the following statements is TRUE for an organism that has a.pdf
Which of the following statements is TRUE for an organism that has a.pdf
 
what is a trans isomerSolutiontrans isomer is a form of geomet.pdf
what is a trans isomerSolutiontrans isomer is a form of geomet.pdfwhat is a trans isomerSolutiontrans isomer is a form of geomet.pdf
what is a trans isomerSolutiontrans isomer is a form of geomet.pdf
 
A) explain why infections occur frequently in patients with lymp.pdf
A) explain why infections occur frequently in patients with lymp.pdfA) explain why infections occur frequently in patients with lymp.pdf
A) explain why infections occur frequently in patients with lymp.pdf
 
What are the benefits and major problems of the fiscal policy and mo.pdf
What are the benefits and major problems of the fiscal policy and mo.pdfWhat are the benefits and major problems of the fiscal policy and mo.pdf
What are the benefits and major problems of the fiscal policy and mo.pdf
 
This is for my immunology course. I am struggling to understand this.pdf
This is for my immunology course. I am struggling to understand this.pdfThis is for my immunology course. I am struggling to understand this.pdf
This is for my immunology course. I am struggling to understand this.pdf
 
The superior portion of the sternum it the ____. glenoid fossa body.pdf
The superior portion of the sternum it the ____.  glenoid fossa  body.pdfThe superior portion of the sternum it the ____.  glenoid fossa  body.pdf
The superior portion of the sternum it the ____. glenoid fossa body.pdf
 
The half-life of a particular element is 410 days. What is its decay.pdf
The half-life of a particular element is 410 days. What is its decay.pdfThe half-life of a particular element is 410 days. What is its decay.pdf
The half-life of a particular element is 410 days. What is its decay.pdf
 
Suppose events A and B are mutually exclusive and at least one of th.pdf
Suppose events A and B are mutually exclusive and at least one of th.pdfSuppose events A and B are mutually exclusive and at least one of th.pdf
Suppose events A and B are mutually exclusive and at least one of th.pdf
 
Q1. Why are the birds discussed in this lab called Darwins finches.pdf
Q1. Why are the birds discussed in this lab called Darwins finches.pdfQ1. Why are the birds discussed in this lab called Darwins finches.pdf
Q1. Why are the birds discussed in this lab called Darwins finches.pdf
 
Preganglionic sympathetic neurons and postganglionic sympathetic neur.pdf
Preganglionic sympathetic neurons and postganglionic sympathetic neur.pdfPreganglionic sympathetic neurons and postganglionic sympathetic neur.pdf
Preganglionic sympathetic neurons and postganglionic sympathetic neur.pdf
 
Please answer this in a simple way and short. thank youQ What are.pdf
Please answer this in a simple way and short. thank youQ What are.pdfPlease answer this in a simple way and short. thank youQ What are.pdf
Please answer this in a simple way and short. thank youQ What are.pdf
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 

Write code to open and read from a file called numbers this file c.pdf

  • 1. Write code to: open and read from a file called numbers this file contains a comma-separated list of numbers (example: 4, 5, 0, 3, 2, 1, 0, 7) count the number of "Os" in the file print the result to a file called output (example: the file contained 2 zeros) Use exception handling to handle the lO Exceptions. (Do not use "throws lO Exception") Solution import java.util.*; import java.io.File; import java.io.IOException; public class ReadFile { public static void main(String[] args) throws IOException { Scanner textfile = new Scanner(new File("Some_Numbers.txt")); filereader(textfile); } static void filereader(Scanner textfile) { int i = 0; int sum = 0; while(i <= 19) { System.out.println(textfile.nextInt()); sum = sum + textfile.nextInt(); i++; } } }