These are trick questions read them carefully #1 Analyze the following code. dou
ID: 3570061 • Letter: T
Question
These are trick questions read them carefully
#1 Analyze the following code.
double sum = 0;
double d;
for (d = 0; d < 10; d = d + 0.1 )
{
sum = sum + d;
}
a.The program has a syntax error because the semicolons in the for loop are in the wrong place.
#2 What is y after the following for loop statement is executed?
int y = 0;
for (int i=0; i < 10; i ++)
{
y ++;
}
a. 9
#3 Array arr is declared and initialized in the following line of code:
int [ ] arr = {10, 7, 3, 5, 9};
What is arr[3] - arr[1]?
#4 Which of the following is a valid array declaration and initialization?
a. char [ ] charArray;
charArray = new char[26];
b. int [ ] words;
words = new words[10];
c. char [ ] charArray;
charArray = 15;
d. double [3] nums;
#5 Consider the following code fragment:
int [ ] list;
list = new int[10];
for (int i = 0; i <= 10; i = i + 1)
{
list[i] = 0;
}
Which of the following statements is true?
a.The loop body will execute 9 times
#6 Assume the declaration of the method xMethod is as follows. This means that xMethod is sent one object that is an array of double values.
public static void xMethod(double [ ] a);
Which of the following could be used to call xMethod?
a. xMethod(5.7);
b. xMethod(
b.The program has a syntax error because the control variable in the for loop cannot be double.Explanation / Answer
1) d
2) a
3) c
4) a
5) d
6) d
7) a
8) a
9) a
10) b
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.