What is the type of the variable x based on the code below: double[][][][] dArra
ID: 3687026 • Letter: W
Question
What is the type of the variable x based on the code below:
double[][][][] dArray = new double[4][4][7][3];
x = dArray[1][3];
Declare and instantiate an array that is capable of storing the number of points scored for each of 5 starting basketball players on 2 different teams.
Suppose you have a single dimensional array of type int with the identifier favoriteNumbers that stores the results of a survey of people’s favorite number. You are interested to see how many of the people who took the survey have the same favorite number as you do. Write some java code that will tell you the number of survey respondents who have the same favorite number as you do. You can assume you have a variable of type int with the identifier myFavNum which has already been declared and initialized that can be used as part of your solution.
What is the output of the following code:
String[] words = {“Du”, “hast”, “mich”};
for(int a = 0; a < 3; a++){
for(int b = 0; b <= a; b++) {
System.out.print(words[b] + “ ”);
}
System.out.print(“ ”);
}
Explanation / Answer
1.
double[][][][] dArray = new double[4][4][7][3];
x = dArray[1][3];
dArray is an three-dimensional array.
so, x = dArray[1][3] : x is one dimensional double aray
2. int[][] points = new int[2][5];
3.
public static void main(String[] args) {
int myFavNum = 6;
int[] favoriteNumbers = new int[10]; // lets say size is 10
int count = 0;
for(int i=0; i<10; i++)
if(favoriteNumbers[i] == myFavNum)
count++;
System.out.println("Number of people with same favorite number: "+count);
}
4.
String[] words = {"Du", "hast", "mich"};
for(int a = 0; a < 3; a++){
for(int b = 0; b <= a; b++) {
System.out.print(words[b] + " ");
}
System.out.print(" ");
}
Output:
Du
Du hast
Du hast mich
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.