Java Varargs - Simple Addition

  • + 0 comments

    class Add { public void add(int... x) { //int r = 0; String seperator = ""; int count = 0; int result = 0; for(int a : x) { //System.out.println(count+a); count = count + a; //System.out.println(a); System.out.print(seperator +a); seperator = "+";

       }
       result = count;
       System.out.print("="+result);
       System.out.println();
    

    } }