Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You need to output a number of values with some separating character (such as a

ID: 3827962 • Letter: Y

Question

You need to output a number of values with some separating character (such as a comma, colon, space, tab, etc.) on a line, but you don't know in advance how many values you'll have to print, and you also want to make sure that the character after the last value on the line is not your separating character. i.e., you want to print: a:b:c rather than a:b:c For this question, write a variable arity method named printlnt() that takes any number of parameters of type int and prints out the parameters separated by a space on a single line. After the last integer on the line, there must be no space, only the newline character.

Explanation / Answer

Here is the required method.

public void printInt(int... arguments) throws Exception {
int l = arguments.length;
if (l > 0)
{
System.out.print(arguments[0]);
for(int i = 1; i < l; i++)
{
System.out.print(" " + arguments[i]);
}
System.out.println();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote