Snippets

Ettar Java - Zaunpfahlproblem mit Boolean

Created by Ettar
public class Sum {
    public static void main(String[] ARGS){
        int[] zahlen = {102,119,136,153,170,187};
        int sum=0;
        boolean plus=false;
        for(int i=0;i<zahlen.length;i++){
            if(plus){
                System.out.print(" + ");
            }
            else{
                plus=true;
            }
            System.out.print(zahlen[i]);
            sum+=zahlen[i];
        }
        System.out.print(" = " + sum);
    }
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.