SlideShare a Scribd company logo
Change given Java code to return the sum of a comma separated integer list scanned from input
file. Please do NOT use any BufferedReader methods, this needs to be done with scanner. and
ONLY modify the body of the public int Problem method.
The code works fine for a file of ints, I just need it adjusted to meet the new input scenario which
will only be txt files containing one line of ints seperated by commas. Explain as much as
possible, I am new and need to understand what and why changes were made.
package Mod4;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Problem1 {
public static void main(String[] args) {
new Problem1();
}
public Problem1() {
int problem1Solution = Problem(new File("Problem1.txt"));
System.out.println(problem1Solution);
}
public int Problem(File file) {
//ONLY MODIFY CODE BELOW HERE
int sum = 0;
try {
Scanner scanFile = new Scanner(file);
while (scanFile.hasNextLine()) {
String fileline = scanFile.nextLine();
Scanner lineInput = new Scanner(fileline);
while (lineInput.hasNextInt()) {
sum += lineInput.nextInt();
}
lineInput.close();
}
scanFile.close();
} catch (FileNotFoundException e) {
System.out.println("File not found.");
}
return sum;
}
}
Change given Java code to return the sum of a comma separated integer.pdf

More Related Content

Similar to Change given Java code to return the sum of a comma separated integer.pdf

Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
zynofustechnology
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
Deniz Oguz
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
dunhamadell
 
Tech talk
Tech talkTech talk
Tech talk
Preeti Patwa
 
i am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfi am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdf
deepaksatrker
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
josephineboon366
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
michael1810
 
ExtraFileIO.pptx
ExtraFileIO.pptxExtraFileIO.pptx
ExtraFileIO.pptx
NguynThiThanhTho
 
Some useful tips with qtp
Some useful tips with qtpSome useful tips with qtp
Some useful tips with qtp
Sandeep
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
ducquoc_vn
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
Hamid Ghorbani
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
Singamvineela
 
What’s New In Python 3.11 & Python 3.11.3 ?
What’s New In Python 3.11 & Python 3.11.3 ?What’s New In Python 3.11 & Python 3.11.3 ?
What’s New In Python 3.11 & Python 3.11.3 ?
Inexture Solutions
 
(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises
Nico Ludwig
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docx
oscars29
 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntuKhurshid Asghar
 
Java8 features
Java8 featuresJava8 features
Java8 features
Elias Hasnat
 
Chapter10
Chapter10Chapter10
Chapter10
vishalw24
 
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
jorgeulises3
 
JDK1.7 features
JDK1.7 featuresJDK1.7 features
JDK1.7 features
india_mani
 

Similar to Change given Java code to return the sum of a comma separated integer.pdf (20)

Python Interview Questions For Experienced
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
Tech talk
Tech talkTech talk
Tech talk
 
i am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfi am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdf
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
 
ExtraFileIO.pptx
ExtraFileIO.pptxExtraFileIO.pptx
ExtraFileIO.pptx
 
Some useful tips with qtp
Some useful tips with qtpSome useful tips with qtp
Some useful tips with qtp
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Python Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptxPython Modules, executing modules as script.pptx
Python Modules, executing modules as script.pptx
 
What’s New In Python 3.11 & Python 3.11.3 ?
What’s New In Python 3.11 & Python 3.11.3 ?What’s New In Python 3.11 & Python 3.11.3 ?
What’s New In Python 3.11 & Python 3.11.3 ?
 
(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises
 
The program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docxThe program reads data from two files, itemsList-0x.txt and .docx
The program reads data from two files, itemsList-0x.txt and .docx
 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntu
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Chapter10
Chapter10Chapter10
Chapter10
 
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdfptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
ptu3-harvey-m-deitel-paul-j-deitel-tem-r-nieto-contributor-paul-j-deitel.pdf
 
JDK1.7 features
JDK1.7 featuresJDK1.7 features
JDK1.7 features
 

More from akknit

Case study- A number of people- including children- became ill several.pdf
Case study- A number of people- including children- became ill several.pdfCase study- A number of people- including children- became ill several.pdf
Case study- A number of people- including children- became ill several.pdf
akknit
 
Case Study- Amanda Tremblay at Citrine Software Solutions (HBS) A- Ide.pdf
Case Study- Amanda Tremblay at Citrine Software Solutions (HBS) A- Ide.pdfCase Study- Amanda Tremblay at Citrine Software Solutions (HBS) A- Ide.pdf
Case Study- Amanda Tremblay at Citrine Software Solutions (HBS) A- Ide.pdf
akknit
 
CASE STUDY The graduate admissions process at begins with an applicant.pdf
CASE STUDY The graduate admissions process at begins with an applicant.pdfCASE STUDY The graduate admissions process at begins with an applicant.pdf
CASE STUDY The graduate admissions process at begins with an applicant.pdf
akknit
 
Case study Read the following case study and write your report about t.pdf
Case study Read the following case study and write your report about t.pdfCase study Read the following case study and write your report about t.pdf
Case study Read the following case study and write your report about t.pdf
akknit
 
Case Study 2 mon the falt and identified as high risk for falls due to.pdf
Case Study 2 mon the falt and identified as high risk for falls due to.pdfCase Study 2 mon the falt and identified as high risk for falls due to.pdf
Case Study 2 mon the falt and identified as high risk for falls due to.pdf
akknit
 
CASE STUDY -70- A 27-year-old black male construction worker suddenly.pdf
CASE STUDY -70- A 27-year-old black male construction worker suddenly.pdfCASE STUDY -70- A 27-year-old black male construction worker suddenly.pdf
CASE STUDY -70- A 27-year-old black male construction worker suddenly.pdf
akknit
 
Carlos Cantu- a food scientist at the International Kitchens Corporati.pdf
Carlos Cantu- a food scientist at the International Kitchens Corporati.pdfCarlos Cantu- a food scientist at the International Kitchens Corporati.pdf
Carlos Cantu- a food scientist at the International Kitchens Corporati.pdf
akknit
 
CASE 6-6 Bill DeBurger- ln-Charge AccountantBuestions- inientory tieno.pdf
CASE 6-6 Bill DeBurger- ln-Charge AccountantBuestions- inientory tieno.pdfCASE 6-6 Bill DeBurger- ln-Charge AccountantBuestions- inientory tieno.pdf
CASE 6-6 Bill DeBurger- ln-Charge AccountantBuestions- inientory tieno.pdf
akknit
 
Carmen Communications reported the following figures from its adjusted.pdf
Carmen Communications reported the following figures from its adjusted.pdfCarmen Communications reported the following figures from its adjusted.pdf
Carmen Communications reported the following figures from its adjusted.pdf
akknit
 
Carrboro has three equal-sized groups of people- (1) Type A people con.pdf
Carrboro has three equal-sized groups of people- (1) Type A people con.pdfCarrboro has three equal-sized groups of people- (1) Type A people con.pdf
Carrboro has three equal-sized groups of people- (1) Type A people con.pdf
akknit
 
Chemolithotrophs use the same chemical for their PED- energy source an.pdf
Chemolithotrophs use the same chemical for their PED- energy source an.pdfChemolithotrophs use the same chemical for their PED- energy source an.pdf
Chemolithotrophs use the same chemical for their PED- energy source an.pdf
akknit
 
Check Your Recall Question 7-5 Homework - Answered - Due Mar 2nd- 12-0.pdf
Check Your Recall Question 7-5 Homework - Answered - Due Mar 2nd- 12-0.pdfCheck Your Recall Question 7-5 Homework - Answered - Due Mar 2nd- 12-0.pdf
Check Your Recall Question 7-5 Homework - Answered - Due Mar 2nd- 12-0.pdf
akknit
 
Check the countries whose economies are best described as -mixed-- com (1).pdf
Check the countries whose economies are best described as -mixed-- com (1).pdfCheck the countries whose economies are best described as -mixed-- com (1).pdf
Check the countries whose economies are best described as -mixed-- com (1).pdf
akknit
 
check both answers please During DNA synthesis- the lagging strand is.pdf
check both answers please During DNA synthesis- the lagging strand is.pdfcheck both answers please During DNA synthesis- the lagging strand is.pdf
check both answers please During DNA synthesis- the lagging strand is.pdf
akknit
 
Characteristics of nonculture techniques include (Select all that appl.pdf
Characteristics of nonculture techniques include (Select all that appl.pdfCharacteristics of nonculture techniques include (Select all that appl.pdf
Characteristics of nonculture techniques include (Select all that appl.pdf
akknit
 
Chapter Review Questions 2- A person who is supine is motinucicated- a.pdf
Chapter Review Questions 2- A person who is supine is motinucicated- a.pdfChapter Review Questions 2- A person who is supine is motinucicated- a.pdf
Chapter Review Questions 2- A person who is supine is motinucicated- a.pdf
akknit
 
Chapter 7- Closing Case- Boeing and Airbus Are in a Dogfight over Ille.pdf
Chapter 7- Closing Case- Boeing and Airbus Are in a Dogfight over Ille.pdfChapter 7- Closing Case- Boeing and Airbus Are in a Dogfight over Ille.pdf
Chapter 7- Closing Case- Boeing and Airbus Are in a Dogfight over Ille.pdf
akknit
 
CASE FILE Gas Gangrene A 77-year-old male resident of southern Colorad.pdf
CASE FILE Gas Gangrene A 77-year-old male resident of southern Colorad.pdfCASE FILE Gas Gangrene A 77-year-old male resident of southern Colorad.pdf
CASE FILE Gas Gangrene A 77-year-old male resident of southern Colorad.pdf
akknit
 
Case Studies- Case 1- A sexually active college student went to her OB.pdf
Case Studies- Case 1- A sexually active college student went to her OB.pdfCase Studies- Case 1- A sexually active college student went to her OB.pdf
Case Studies- Case 1- A sexually active college student went to her OB.pdf
akknit
 
Case History- Tracking a -Patchwork Quilt- Pathogen Nine-month-old Eva.pdf
Case History- Tracking a -Patchwork Quilt- Pathogen Nine-month-old Eva.pdfCase History- Tracking a -Patchwork Quilt- Pathogen Nine-month-old Eva.pdf
Case History- Tracking a -Patchwork Quilt- Pathogen Nine-month-old Eva.pdf
akknit
 

More from akknit (20)

Case study- A number of people- including children- became ill several.pdf
Case study- A number of people- including children- became ill several.pdfCase study- A number of people- including children- became ill several.pdf
Case study- A number of people- including children- became ill several.pdf
 
Case Study- Amanda Tremblay at Citrine Software Solutions (HBS) A- Ide.pdf
Case Study- Amanda Tremblay at Citrine Software Solutions (HBS) A- Ide.pdfCase Study- Amanda Tremblay at Citrine Software Solutions (HBS) A- Ide.pdf
Case Study- Amanda Tremblay at Citrine Software Solutions (HBS) A- Ide.pdf
 
CASE STUDY The graduate admissions process at begins with an applicant.pdf
CASE STUDY The graduate admissions process at begins with an applicant.pdfCASE STUDY The graduate admissions process at begins with an applicant.pdf
CASE STUDY The graduate admissions process at begins with an applicant.pdf
 
Case study Read the following case study and write your report about t.pdf
Case study Read the following case study and write your report about t.pdfCase study Read the following case study and write your report about t.pdf
Case study Read the following case study and write your report about t.pdf
 
Case Study 2 mon the falt and identified as high risk for falls due to.pdf
Case Study 2 mon the falt and identified as high risk for falls due to.pdfCase Study 2 mon the falt and identified as high risk for falls due to.pdf
Case Study 2 mon the falt and identified as high risk for falls due to.pdf
 
CASE STUDY -70- A 27-year-old black male construction worker suddenly.pdf
CASE STUDY -70- A 27-year-old black male construction worker suddenly.pdfCASE STUDY -70- A 27-year-old black male construction worker suddenly.pdf
CASE STUDY -70- A 27-year-old black male construction worker suddenly.pdf
 
Carlos Cantu- a food scientist at the International Kitchens Corporati.pdf
Carlos Cantu- a food scientist at the International Kitchens Corporati.pdfCarlos Cantu- a food scientist at the International Kitchens Corporati.pdf
Carlos Cantu- a food scientist at the International Kitchens Corporati.pdf
 
CASE 6-6 Bill DeBurger- ln-Charge AccountantBuestions- inientory tieno.pdf
CASE 6-6 Bill DeBurger- ln-Charge AccountantBuestions- inientory tieno.pdfCASE 6-6 Bill DeBurger- ln-Charge AccountantBuestions- inientory tieno.pdf
CASE 6-6 Bill DeBurger- ln-Charge AccountantBuestions- inientory tieno.pdf
 
Carmen Communications reported the following figures from its adjusted.pdf
Carmen Communications reported the following figures from its adjusted.pdfCarmen Communications reported the following figures from its adjusted.pdf
Carmen Communications reported the following figures from its adjusted.pdf
 
Carrboro has three equal-sized groups of people- (1) Type A people con.pdf
Carrboro has three equal-sized groups of people- (1) Type A people con.pdfCarrboro has three equal-sized groups of people- (1) Type A people con.pdf
Carrboro has three equal-sized groups of people- (1) Type A people con.pdf
 
Chemolithotrophs use the same chemical for their PED- energy source an.pdf
Chemolithotrophs use the same chemical for their PED- energy source an.pdfChemolithotrophs use the same chemical for their PED- energy source an.pdf
Chemolithotrophs use the same chemical for their PED- energy source an.pdf
 
Check Your Recall Question 7-5 Homework - Answered - Due Mar 2nd- 12-0.pdf
Check Your Recall Question 7-5 Homework - Answered - Due Mar 2nd- 12-0.pdfCheck Your Recall Question 7-5 Homework - Answered - Due Mar 2nd- 12-0.pdf
Check Your Recall Question 7-5 Homework - Answered - Due Mar 2nd- 12-0.pdf
 
Check the countries whose economies are best described as -mixed-- com (1).pdf
Check the countries whose economies are best described as -mixed-- com (1).pdfCheck the countries whose economies are best described as -mixed-- com (1).pdf
Check the countries whose economies are best described as -mixed-- com (1).pdf
 
check both answers please During DNA synthesis- the lagging strand is.pdf
check both answers please During DNA synthesis- the lagging strand is.pdfcheck both answers please During DNA synthesis- the lagging strand is.pdf
check both answers please During DNA synthesis- the lagging strand is.pdf
 
Characteristics of nonculture techniques include (Select all that appl.pdf
Characteristics of nonculture techniques include (Select all that appl.pdfCharacteristics of nonculture techniques include (Select all that appl.pdf
Characteristics of nonculture techniques include (Select all that appl.pdf
 
Chapter Review Questions 2- A person who is supine is motinucicated- a.pdf
Chapter Review Questions 2- A person who is supine is motinucicated- a.pdfChapter Review Questions 2- A person who is supine is motinucicated- a.pdf
Chapter Review Questions 2- A person who is supine is motinucicated- a.pdf
 
Chapter 7- Closing Case- Boeing and Airbus Are in a Dogfight over Ille.pdf
Chapter 7- Closing Case- Boeing and Airbus Are in a Dogfight over Ille.pdfChapter 7- Closing Case- Boeing and Airbus Are in a Dogfight over Ille.pdf
Chapter 7- Closing Case- Boeing and Airbus Are in a Dogfight over Ille.pdf
 
CASE FILE Gas Gangrene A 77-year-old male resident of southern Colorad.pdf
CASE FILE Gas Gangrene A 77-year-old male resident of southern Colorad.pdfCASE FILE Gas Gangrene A 77-year-old male resident of southern Colorad.pdf
CASE FILE Gas Gangrene A 77-year-old male resident of southern Colorad.pdf
 
Case Studies- Case 1- A sexually active college student went to her OB.pdf
Case Studies- Case 1- A sexually active college student went to her OB.pdfCase Studies- Case 1- A sexually active college student went to her OB.pdf
Case Studies- Case 1- A sexually active college student went to her OB.pdf
 
Case History- Tracking a -Patchwork Quilt- Pathogen Nine-month-old Eva.pdf
Case History- Tracking a -Patchwork Quilt- Pathogen Nine-month-old Eva.pdfCase History- Tracking a -Patchwork Quilt- Pathogen Nine-month-old Eva.pdf
Case History- Tracking a -Patchwork Quilt- Pathogen Nine-month-old Eva.pdf
 

Recently uploaded

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
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
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
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
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
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
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)
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
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
 

Recently uploaded (20)

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 ...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
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
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
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
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
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
 

Change given Java code to return the sum of a comma separated integer.pdf

  • 1. Change given Java code to return the sum of a comma separated integer list scanned from input file. Please do NOT use any BufferedReader methods, this needs to be done with scanner. and ONLY modify the body of the public int Problem method. The code works fine for a file of ints, I just need it adjusted to meet the new input scenario which will only be txt files containing one line of ints seperated by commas. Explain as much as possible, I am new and need to understand what and why changes were made. package Mod4; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Problem1 { public static void main(String[] args) { new Problem1(); } public Problem1() { int problem1Solution = Problem(new File("Problem1.txt")); System.out.println(problem1Solution); } public int Problem(File file) { //ONLY MODIFY CODE BELOW HERE int sum = 0; try { Scanner scanFile = new Scanner(file); while (scanFile.hasNextLine()) { String fileline = scanFile.nextLine(); Scanner lineInput = new Scanner(fileline); while (lineInput.hasNextInt()) { sum += lineInput.nextInt(); } lineInput.close(); } scanFile.close(); } catch (FileNotFoundException e) { System.out.println("File not found."); } return sum; } }