Java Reference
In-Depth Information
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();
}
}
26.
What is the output of the following Java code?
final double
PI = 3.14159;
double
[] cylinderRadii = {3.5, 7.2, 10.5, 9.8, 6.5};
double
[] cylinderHeights = {10.7, 6.5, 12.0, 10.5, 8.0};
double
[] cylinderVolumes =
new double
[5];
for
(
int
i = 0; i < 5; i++)
cylinderVolumes[i] = 2 * PI * cylinderRadii[i]
* cylinderHeights[i];
for
(
int
i = 0; i < 5; i++)
System.out.printf("%d %.2f %.2f %.2f %n",
(i + 1), cylinderRadii[i], cylinderHeights[i],
cylinderVolumes[i]);
27.
When an array is passed as an actual parameter to a method, what is actually
being passed?
Suppose you have the following class:
public class
NamesList
{
28.
private
String[] namesList;
//Constructor with a variable length
//formal parameter
public
NamesList(String ... names)
{
namesList = names;
}
//Method to return namesList as a string
public
String toString()
{
String str = "";
for
(String name : namesList)
str = str + name + "\n";
return
str;
}
}
Search WWH ::
Custom Search