public class ExceptionTest {
private static int[] feld = {3,6,2,0,-2,-1};
static public int berechne(int from,int to, int step){
int sum=10, i=0;
try{
for(i=from;i<=to;i+=step)
sum=sum+(sum/feld);
}catch(ArithmeticException e){
sum=sum+feld[i+1];
}catch(ArrayIndexOutOfBoundsException e){
sum++;
}
finally{
sum= sum*i/2;
}
return sum;
}
static public void main(String[] args)
{
System.out.println(""+berechne(1,4,1));
System.out.println(""+berechne(0,7,2));
}
}
dafür gibt mir mein Compiler
bereche(1,4,1) = 21;
bereche(0,7,2) = 33;
hoffe hab alles richtig abgeschrieben. Danke für Hinweise.
eactor