Question: 40. Consider the program below: public class Test { public static void main(String[] args) { Int[] a; a = new int[10]; for(int i = 0;
40. Consider the program below:
public class Test
{
public static void main(String[] args)
{
Int[] a;
a = new int[10];
for(int i = 0; i < a.length; i++)
a[i] = i + 2;
int result = 0;
for(inti = 0; i < a.length; i++)
result += a[i];
System.out.printf(Result is: %d%n, result);
}
}
The output of this program is:
a. 62
b. 64
c. 65
d. 67
44. Assume array items contain the integer values 0, 2, 4, 6, and 8. Which of the following uses the enhanced for loop to display each value in array items?
a. for(int i = 0 : items.length)
System.out.printf("%dn%, items[i]);
b. for(inti : items) System.out.printf(%d%n, i);
c. for(int i: items) System.out.printf(%d%n, items[i]);
d. for(int i = 0; i < items.length; i++)
System.out.printf("%dn%, items[i]);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
