VarargsTesterpublic class VarargsTester extends Object
Constructors Summary |
---|
public VarargsTester()
|
Methods Summary |
---|
private int[] | getListOfNumbers()
int[] numbers = new int[] {0, 2, 4, 6, 8, 10, 9, 7, 5, 3, 1};
return numbers;
| public static void | main(java.lang.String[] args)
try {
VarargsTester tester = new VarargsTester();
tester.testMaxMethod(System.out);
tester.testPrintMethod(System.out);
tester.testArrayArgs(System.out);
} catch (IOException e) {
e.printStackTrace();
}
| private java.lang.String | print(java.lang.Object values)
StringBuilder sb = new StringBuilder();
for (Object o : values) {
sb.append(o.toString())
.append(" ");
}
return sb.toString();
| public void | testArrayArgs(java.io.PrintStream out)
Object[] obj = new String[] {"Hello", "to", "all", "of", "you"};
out.printf("%s\n", obj);
out.printf("%s\n", (Object)obj);
| public void | testMaxMethod(java.io.PrintStream out)
int[] numbers = getListOfNumbers();
int max = MathUtils.max(numbers);
out.println("Max of list is: " + max);
| public void | testPrintMethod(java.io.PrintStream out)
out.println(print("foo", 23, -12, 1.23, getListOfNumbers()));
|
|