1a) Create file, file1 , with the following values: 7 35 20 -43 -10 6 7 13 12.0
ID: 3792288 • Letter: 1
Question
1a) Create file, file1, with the following values: 7
35 20 -43 -10 6 7 13
12.0 1.5 -3.5 -2.54 3.4 45.34 22.13 true false false true false true false
Deadline: 10:00 pm on Feb 14, 2017
First Name:________________________
1b) Write a program in Java to do the following:
-Open "file1" and read the first value, n, which is supposed to be an integer describing the size of the upcoming arrays of integer, float, and Boolean values.
-Create one-dimensional arrays of n integer, floating point, and Boolean values.
-Populate the three created arrays by reading their values from file1.
-Declare sum as integer and set it to 0.
-Declare sumf as float and set it to 0.0f.
-Use a for loop to go through each element of the Boolean array, and if an element is “true” then add the corresponding element in the integer array to sum, and also add the corresponding element in the floating-point array to sumf.
-Print all three arrays, sum, and sumf.
Explanation / Answer
Answer:
OUTPUT:
Integer Array: 35 20 -43 -10 6 7 13
Float Array: 12.0 1.5 -3.5 -2.54 3.4 45.34 22.13
Boolean Array: true false false true false true false
Sum: 32
Sumf: 54.8
-------------------------------------------------------------------------------------------------------------------------------------------------------------
OUTPUT:
Integer Array: 35 20 -43 -10 6 7 13
Float Array: 12.0 1.5 -3.5 -2.54 3.4 45.34 22.13
Boolean Array: true false false true false true false
Sum: 32
Sumf: 54.8
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.