SlideShare a Scribd company logo
1 of 5
Download to read offline
The output should now look like this:
Row 1 sum: 30
Row 2 sum: 48
Row 3 sum: 55
Count: 12
Grand total: 133
Mean: 11.08
Even numbers: 7
Odd numbers: 5
How to add even and odd numbers counts to existing code
public class Problem {
public static void main(String [] args)
{
int iVal;
int iRow;
int iRowSum;
int iToken;
int totalSum = 0;
int totalEle = 0;
iRowSum = 0;
iRow = 1;
try
{
Scanner ifsInput = new Scanner(new File("c:homestudentlastname/9_1_Input.txt"));
while(ifsInput.hasNextLine())
{
while(ifsInput.hasNextInt())
{
for(iToken = 0; iToken <= 3; iToken++)
{
iVal = ifsInput.nextInt();
iRowSum = iRowSum + iVal;
// increasing count of total element
totalEle++;
}
// adding into totalSum
totalSum = totalSum + iRowSum;
System.out.println("Row " + iRow + " sum: " + iRowSum);
iRowSum = 0;
iRow++;
}
}
// added new code to print grand total and mean value
System.out.println("Count: "+totalEle);
System.out.println("Grand total: "+totalSum);
System.out.println("Mean: "+String.format(".2f", (double)/totalSum/totalEle);
}
catch (FileNotFoundException sMsg)
{
System.out.println("The file cannot be found or opened.");
}
}
}
Solution
Input999.txt( Save this file under D Drive Then the path of the file pointing to it is
D:Input999.txt)
11 22 33 44
22 33 44 55
33 44 55 66
___________________________
Problem.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Problem {
public static void main(String [] args)
{
//Declaring variables
int iVal;
int iRow;
int iRowSum;
int iToken;
double mean=0.0;
int evenCount=0,oddCount=0;
int totalSum = 0;
int totalEle = 0;
iRowSum = 0;
iRow = 1;
try
{
Scanner ifsInput = new Scanner(new File("D:Input999.txt"));
while(ifsInput.hasNextLine())
{
while(ifsInput.hasNextInt())
{
for(iToken = 0; iToken <= 3; iToken++)
{
iVal = ifsInput.nextInt();
//Calculating the even count
if(iVal%2==0)
evenCount++;
//Calculating the odd count
else
oddCount++;
//Calculating the sum of elements in each row
iRowSum = iRowSum + iVal;
// increasing count of total element
totalEle++;
}
// adding into totalSum
totalSum = totalSum + iRowSum;
//Displaying the sum of elements in each row
System.out.println("Row " + iRow + " sum: " + iRowSum);
iRowSum = 0;
iRow++;
}
}
//Displaying the number of elements
System.out.println("Count: "+totalEle);
//Displaying the sum of all elements
System.out.println("Grand total: "+totalSum);
//Calculating the mean
mean=(double)totalSum/totalEle;
//Displaying the mean
System.out.printf("Mean: %.2f ",mean);
//Displaying the number of even nos
System.out.println("Even Numbers :"+evenCount);
//Displaying the number of odd nos
System.out.println("Odd Numbers :"+oddCount);
}
catch (FileNotFoundException sMsg)
{
System.out.println("The file cannot be found or opened.");
}
}
}
_________________________________
Output:
Row 1 sum: 110
Row 2 sum: 154
Row 3 sum: 198
Count: 12
Grand total: 462
Mean: 38.50
Even Numbers :6
Odd Numbers :6
___________Thank You

More Related Content

Similar to The output should now look like this Row 1 sum 30 Row 2 sum.pdf

DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
aathiauto
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docx
dickonsondorris
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
mustkeem khan
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
fantasiatheoutofthef
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
optokunal1
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
bradburgess22840
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdf
rajeshjangid1865
 
import java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdfimport java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdf
apexelectronices01
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
Abed Bukhari
 

Similar to The output should now look like this Row 1 sum 30 Row 2 sum.pdf (19)

DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
Use the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docxUse the following data set that compares age to average years lef.docx
Use the following data set that compares age to average years lef.docx
 
CSharp for Unity Day2
CSharp for Unity Day2CSharp for Unity Day2
CSharp for Unity Day2
 
Java practical
Java practicalJava practical
Java practical
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
54240326 (1)
54240326 (1)54240326 (1)
54240326 (1)
 
54240326 copy
54240326   copy54240326   copy
54240326 copy
 
Lab4
Lab4Lab4
Lab4
 
07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt07-Basic-Input-Output.ppt
07-Basic-Input-Output.ppt
 
Wrapper class
Wrapper classWrapper class
Wrapper class
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
Create a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdfCreate a menu-driven program that will accept a collection of non-ne.pdf
Create a menu-driven program that will accept a collection of non-ne.pdf
 
import java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdfimport java.util.Scanner;public class Digits { public static v.pdf
import java.util.Scanner;public class Digits { public static v.pdf
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 

More from xlynettalampleyxc

what is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfwhat is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdf
xlynettalampleyxc
 
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfThe end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
xlynettalampleyxc
 
Suppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfSuppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdf
xlynettalampleyxc
 
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdfSet up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
xlynettalampleyxc
 
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfSample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
xlynettalampleyxc
 
Practice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfPractice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdf
xlynettalampleyxc
 
Please, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfPlease, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdf
xlynettalampleyxc
 
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfPatient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
xlynettalampleyxc
 
Non-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfNon-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdf
xlynettalampleyxc
 
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfInventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
xlynettalampleyxc
 
In December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfIn December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdf
xlynettalampleyxc
 
In a longitudinal study of attitude toward statistics, a doctoral st.pdf
In a longitudinal study of attitude toward statistics, a doctoral st.pdfIn a longitudinal study of attitude toward statistics, a doctoral st.pdf
In a longitudinal study of attitude toward statistics, a doctoral st.pdf
xlynettalampleyxc
 

More from xlynettalampleyxc (20)

According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdfAccording to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
According to the IRS, 1.1 of tax returns will be audited in 2011. A.pdf
 
Write a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdfWrite a SELECT statement that returns a single value that represents.pdf
Write a SELECT statement that returns a single value that represents.pdf
 
which represents the ground state for the N- ion i. w.ia ere sm.pdf
which represents the ground state for the N- ion  i. w.ia ere sm.pdfwhich represents the ground state for the N- ion  i. w.ia ere sm.pdf
which represents the ground state for the N- ion i. w.ia ere sm.pdf
 
what is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdfwhat is the prediction equation for the median income and incarcerat.pdf
what is the prediction equation for the median income and incarcerat.pdf
 
What is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdfWhat is the ecological and environmental importance of salinityoxyg.pdf
What is the ecological and environmental importance of salinityoxyg.pdf
 
WEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdfWEP has vulnerabilities. Which of the following is not a reason why .pdf
WEP has vulnerabilities. Which of the following is not a reason why .pdf
 
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdfTwo astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
Two astronauts are 2.40 m apart in their spaceship. One speaks to the.pdf
 
The ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdfThe ratio of the probability of disease in an exposed group to the p.pdf
The ratio of the probability of disease in an exposed group to the p.pdf
 
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdfThe end problem in eukaryotic DNA replicationa. is solved by t.pdf
The end problem in eukaryotic DNA replicationa. is solved by t.pdf
 
Suppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdfSuppose that one obtained the following DNA sequence data for the fou.pdf
Suppose that one obtained the following DNA sequence data for the fou.pdf
 
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdfSet up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
Set up a JavaFX GUI-based program that shows a 10 times 10 grid of la.pdf
 
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdfSample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
Sample of DNA isolated from bacterium X contains 17.5 of adenine.pdf
 
Practice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdfPractice using layouts Anderson, Franceschi import javax..pdf
Practice using layouts Anderson, Franceschi import javax..pdf
 
Please, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdfPlease, I need a correct answer and clear explanation. open image an.pdf
Please, I need a correct answer and clear explanation. open image an.pdf
 
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdfPatient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
Patient 2 Patient #2 Jan Johnson Next, Dr. Gupta sees Jan Johnson. .pdf
 
Non-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdfNon-math and physics question, but engineering orientated.Identify.pdf
Non-math and physics question, but engineering orientated.Identify.pdf
 
Name three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdfName three properties of the waveform that can be changed with the m.pdf
Name three properties of the waveform that can be changed with the m.pdf
 
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdfInventory Valuation FIFO, LIFO, and Average The company reported the.pdf
Inventory Valuation FIFO, LIFO, and Average The company reported the.pdf
 
In December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdfIn December 2009, a 45-year-old female presented to the emergency dep.pdf
In December 2009, a 45-year-old female presented to the emergency dep.pdf
 
In a longitudinal study of attitude toward statistics, a doctoral st.pdf
In a longitudinal study of attitude toward statistics, a doctoral st.pdfIn a longitudinal study of attitude toward statistics, a doctoral st.pdf
In a longitudinal study of attitude toward statistics, a doctoral st.pdf
 

Recently uploaded

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 lesson
httgc7rh9c
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 
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
AnaAcapella
 

Recently uploaded (20)

FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 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...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.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...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
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)
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
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
 
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
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
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
 

The output should now look like this Row 1 sum 30 Row 2 sum.pdf

  • 1. The output should now look like this: Row 1 sum: 30 Row 2 sum: 48 Row 3 sum: 55 Count: 12 Grand total: 133 Mean: 11.08 Even numbers: 7 Odd numbers: 5 How to add even and odd numbers counts to existing code public class Problem { public static void main(String [] args) { int iVal; int iRow; int iRowSum; int iToken; int totalSum = 0; int totalEle = 0; iRowSum = 0; iRow = 1; try { Scanner ifsInput = new Scanner(new File("c:homestudentlastname/9_1_Input.txt")); while(ifsInput.hasNextLine()) { while(ifsInput.hasNextInt()) { for(iToken = 0; iToken <= 3; iToken++) { iVal = ifsInput.nextInt();
  • 2. iRowSum = iRowSum + iVal; // increasing count of total element totalEle++; } // adding into totalSum totalSum = totalSum + iRowSum; System.out.println("Row " + iRow + " sum: " + iRowSum); iRowSum = 0; iRow++; } } // added new code to print grand total and mean value System.out.println("Count: "+totalEle); System.out.println("Grand total: "+totalSum); System.out.println("Mean: "+String.format(".2f", (double)/totalSum/totalEle); } catch (FileNotFoundException sMsg) { System.out.println("The file cannot be found or opened."); } } } Solution Input999.txt( Save this file under D Drive Then the path of the file pointing to it is D:Input999.txt) 11 22 33 44 22 33 44 55 33 44 55 66 ___________________________ Problem.java
  • 3. import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Problem { public static void main(String [] args) { //Declaring variables int iVal; int iRow; int iRowSum; int iToken; double mean=0.0; int evenCount=0,oddCount=0; int totalSum = 0; int totalEle = 0; iRowSum = 0; iRow = 1; try { Scanner ifsInput = new Scanner(new File("D:Input999.txt")); while(ifsInput.hasNextLine()) { while(ifsInput.hasNextInt()) { for(iToken = 0; iToken <= 3; iToken++) { iVal = ifsInput.nextInt(); //Calculating the even count if(iVal%2==0) evenCount++; //Calculating the odd count else oddCount++;
  • 4. //Calculating the sum of elements in each row iRowSum = iRowSum + iVal; // increasing count of total element totalEle++; } // adding into totalSum totalSum = totalSum + iRowSum; //Displaying the sum of elements in each row System.out.println("Row " + iRow + " sum: " + iRowSum); iRowSum = 0; iRow++; } } //Displaying the number of elements System.out.println("Count: "+totalEle); //Displaying the sum of all elements System.out.println("Grand total: "+totalSum); //Calculating the mean mean=(double)totalSum/totalEle; //Displaying the mean System.out.printf("Mean: %.2f ",mean); //Displaying the number of even nos System.out.println("Even Numbers :"+evenCount); //Displaying the number of odd nos System.out.println("Odd Numbers :"+oddCount);
  • 5. } catch (FileNotFoundException sMsg) { System.out.println("The file cannot be found or opened."); } } } _________________________________ Output: Row 1 sum: 110 Row 2 sum: 154 Row 3 sum: 198 Count: 12 Grand total: 462 Mean: 38.50 Even Numbers :6 Odd Numbers :6 ___________Thank You