double sum(double x){ return x*(x+1)/2.0; }
private void computeButtonMouseClicked(java.awt.event.MouseEvent evt) { int answer=0; int n=Convert.toInt(nField.getText()); if(n<0){ loopLabel.setText("n must be positive"); }else{ for (int i=1; i<=n; i++){ answer+=i; } loopLabel.setText(""+answer); methodLabel.setText(""+sum(n));
}
}