Workshop 2007 JRE Java Support
Installation
Home
CalcTool
Java Applets
Friends/Family
Gardening
Woodworking
Forums
double sum(double x){
 	return  x*(x+1)/2.0;
}

 

Note that I used “2.0” instead of “2”.  This clearly indicates to the compiler (and user) that I am doing arithmetic with double instead of int

 

int sum(int  x){
       return  x*(x+1)/2;
}            

 

Sample Code 3