1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
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); } }
You can clone a snippet to your computer for local editing. Learn more.