Java Reference
In-Depth Information
12. What is the output of the following program?
public class Exercise12
{
public static void main(String[] args)
{
int [] alpha = new int[5];
alpha[0] = 5;
for ( int count = 1; count < 5; count++)
{
alpha[count] = 5 * count + 10;
alpha[count - 1] = alpha[count] - 4;
}
System.out.print("List elements: ");
for ( int count = 0; count < 5; count++)
System.out.print(alpha[count] + " ");
System.out.println();
}
}
13. What is the output of the following program?
public class Exercise13
{
public static void main(String[] args)
{
int [] one = new int[5];
int [] two = new int[10];
for ( int j = 0; j < 5; j++)
one[j] = 5 * j + 3;
System.out.print("One contains: ");
for ( int j = 0; j < 5; j++)
System.out.print(one[j] + " ");
System.out.println();
for ( int j = 0; j < 5; j++)
{
two[j] = 2 * one[j] - 1;
two[j + 5] = one[4 - j] + two[j];
}
System.out.print("Two contains: ");
for ( int j = 0; j < 10; j++)
System.out.print(two[j] + " ");
System.out.println();
}
}
Search WWH ::




Custom Search