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

Use java to solve this. This question is an example that often occurs in practic

ID: 3824182 • Letter: U

Question

Use java to solve this.

This question is an example that often occurs in practice: 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 print int() 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

Hi, Please find my implementation.

Please let me know in case of any issue.

public class MyTest {

  

   public static void println(int ... var_args){

      

       for(int i=0; i<var_args.length; i++){

           if(i == var_args.length)

               System.out.println(var_args[i]);

           else

               System.out.print(var_args[i]+" ");

       }

   }

   public static void main(String[] args) {

      

       println(1,2,3,4);

   }

}