hacker rank 48th java solution(java varargs-simple addition)

48. java varargs-simple addition


class Add
  
  public void add(int... intArgs){
     int sum=0;
  String sep ="";
    for(int i:intArgs){
      sum=sum+i;
      System.out.print(sep + i);
    sep ="+";
    }
    System.out.println("=" + sum);
  }  

}


Compiler Message
Success
Input (stdin)Download
1
2
3
4
5
6
Expected OutputDownload
1+2=3
1+2+3=6
1+2+3+4+5=15
1+2+3+4+5+6=21

Comments

Popular posts from this blog

Amazon Web Services

Google Code-In mentorship experience :)

Hacker Rank all java and python problem solutions