Created
January 14, 2014 12:14
-
-
Save ph3nx/8417394 to your computer and use it in GitHub Desktop.
Die Methode quadratzahlen(int n) erzeugt Anzahl n Quadratzahlen und gibt diese addiert, sowie deren Durchschnitt aus.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Arrays { | |
public static void main(String[] args) { | |
int[] numbers = new int[5]; | |
numbers[0] = 5; | |
int l = numbers.length; | |
ausgabe("Länge des arrays", l); | |
quadratzahlen(100); | |
} | |
private static void ausgabe(String s, int val){ | |
System.out.println("\""+s+"\" ist "+val); | |
} | |
private static void quadratzahlen(int n){ | |
int addiert = 0; | |
int[] qz = new int[n]; | |
for (int i=0; i<n; i++){ | |
qz[i] = (i+1) * (i+1); | |
} | |
for (int i=0; i<qz.length; i++){ | |
System.out.println("Quadratzahl #"+i+" beträgt "+qz[i]); | |
addiert += qz[i]; | |
} | |
System.out.println("Alle Zahlen addiert: "+addiert); | |
System.out.println("Durchschnitt der Zahlen: "+addiert/qz.length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment