Tuesday, March 6, 2007

Variable number of arguments in Java

Did you know that java too supports variable number of arguments?

Here's an example.

Try it.

class test{
public static void main(String args[]){
System.out.println("The sum is " + calculateSum(1,2,3));
}

private static int calculateSum(int... values){
int sum = 0;
for (int counter = 0; counter < values.length; counter ++){
sum = sum + values[counter];
}
return sum;
}
}


It works with both primitive data types and objects.

Never Be condemned

Yes. Never be condemned. Whatever you do, for whatever action you do, there is some one to criticize you and embarass you. But, never say die. Never get condemned or discouraged. There are always people who condemn and discourage you even for a hard and good work. They will be around you when you are happy but will not be in your sight at all when you are in despair. Before doing anything, think twice or thrice. Think how much benefit does that action give you. Think whether it affects others. Prioritize between your benefit and the others' damage and perform the action. But, many dont do that, as far as i have seen. When you tell them that their action affected me or will affect others, they call you as fools and criticize you for being such a foolish guy and embarass you. But, never get condemned by those words. Never get condemned by their sharp but useles words. Think as if you havent heard those words. Much important than that is, be careful with that person who mentioned you as a fool. I have seen many people who do things that embarass and insult others but still they dont realize that. I dont exclude myself. It may include me also. i dont know. But still I write what i feel and I write what i learnt from the recent past. i write what itched me for a long time every day.

I say again, never be condemned. The person who condemned you may go. But you will be the person who gets affected mentally and therefore lose your track in your life journey. So, never mind the condemnations. I dont say to neglect every sharp, pricking word. Think whether those words really are true. If true, then its your discretion on how to proceed. But, if false, never give your ear to that. Become a deaf at that time. I say again, Never get condemned.