package forstatement6;
public class Forstatement6 {
public static void main(String args[]) {
forStatementTest();
}
public static void forStatementTest(){
int tempN=10;
System.out.println("1 add to "+tempN+" is: "+addToN(tempN));
tempN=0;
System.out.println("1 add to "+tempN+" is: "+addToN(tempN));
int tempSteplength=1;
tempN=10;
System.out.println("1 add to "+tempN + " with step length "+tempSteplength+" is: "+ addToNWithSteplength(tempN,tempSteplength));
tempSteplength=2;
System.out.println("1 add to "+tempN + " with step length "+tempSteplength+" is: "+ addToNWithSteplength(tempN,tempSteplength));
}
public static int addToN(int paraN) {
int resultSum=0;
for (int i=1;i<=paraN;i++ ) {
resultSum+=i;
}
return resultSum;
}
public static int addToNWithSteplength(int paraN,int paraSteplength) {
int resultSum=0;
for(int i=1;i<=paraN;i+=paraSteplength) {
resultSum+=i;
}
return resultSum;
}
}