We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.lang.reflect.*;importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;classAdd{voidadd(int...nums){intsum=0;for(inti=0;i<nums.length;i++){sum+=nums[i];if(i>0){System.out.print("+");}System.out.print(nums[i]);}System.out.println("="+sum);}}publicclassSolution{publicstaticvoidmain(String[]args){try{BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));intn1=Integer.parseInt(br.readLine());intn2=Integer.parseInt(br.readLine());intn3=Integer.parseInt(br.readLine());intn4=Integer.parseInt(br.readLine());intn5=Integer.parseInt(br.readLine());intn6=Integer.parseInt(br.readLine());Addob=newAdd();ob.add(n1,n2);ob.add(n1,n2,n3);ob.add(n1,n2,n3,n4,n5);ob.add(n1,n2,n3,n4,n5,n6);Method[]methods=Add.class.getDeclaredMethods();Set<String>set=newHashSet<>();booleanoverload=false;for(inti=0;i<methods.length;i++){if(set.contains(methods[i].getName())){overload=true;break;}set.add(methods[i].getName());}if(overload){thrownewException("Overloading not allowed");}}catch(Exceptione){e.printStackTrace();}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Varargs - Simple Addition
You are viewing a single comment's thread. Return to all comments →