Write down a java program segment to do the following: -Declare and initialize a
ID: 3816052 • Letter: W
Question
Write down a java program segment to do the following: -Declare and initialize an array of integers as follows: 1 2 5 -6 -2 -Declare and initialize an array of floating point numbers as follows: -1.2 2.1 3.3 0.2 -6.0 -Declare and initialize an array of Boolean values as follows: true false false true false -Add each element of the first array to the corresponding element of the second array if the corresponding Boolean element in the third array is true. import java.util.*; import java.io.*; public class prog{public static void main(String []args){}}Explanation / Answer
Hi, Please find my implementation.
Please let me know in case of any issue.
public class Prog {
public static void main(String[] args) {
// declaring array
int[] intArr = {1,2,5,-6,2};
float[] fArr = {-1.2f, 2.1f, 3.3f, 0.2f,-6.0f };
boolean[] bArr = {true, false,false, true, false};
for(int i=0; i<intArr.length; i++){
if(bArr[i]){
float sum = intArr[i] + fArr[i];
System.out.println(sum + " ");
}
}
System.out.println();
}
}
/*
Sample run:
-0.20000005
-5.8
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.