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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started