An example code is given below..
public int add(char a,int... num ) //variable length argument
{
int no=num.length;
int sum=0;
for(int i=0;i!=no;i++)
sum+=num[i];
sum+=a;
return sum;
}
public static void main(String[] args) {
Main m=new Main();
System.out.println(m.add('A',10,20));
System.out.println(m.add('A',10,20,30));
}
No comments:
Post a Comment