Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WieOft {
- /*--- Aufgabe 4.1 (einfach) ---
- *
- * Schreibe ein Programm das ein Integer Array mit vielen Werten besitzt
- * (Vorlage für Array http://pastebin.com/xndJH35g ).
- * Das Programm soll nun mit Hilfe einer Schleife zählen wie oft eine bestimmte Zahl im Array vorkommt
- * und das Ergebnis auf der Konsole ausgeben.
- * (Zum überprüfen: 3 gibt es 7 mal, 4 gibt es 14 mal in der Vorlage
- */
- public static void main(String[] args) {
- int[] array = new int[]{0,85,47,46,9,74,5,698,4,56,8,475,6,4,5,8,56,84,4584,84,
- 56,4,656,4,64,5,6,54,1,6456,2,4556,142315,31,450,0,12321,3,2,12,5,5,3,8,
- 5,4,867,51,3,589,4,13,587,-4,1,68,456,46,7,3,54,1,36,4,321,86,4,4,21,412,
- 42,698,936,536,93,545,472,42,68,34,20,0,985,741,3,463,745,43,4,1,24,15,82,
- 30,0,894,65468,4,56,484,654,68,4,5,123,213213,54,6,46,87,4,50,0,548,565,4,
- 2,2,3,9,51,51,2,6,92,9,0,3};
- int wert = -1;
- int count = 0;
- for(int i = 0; i < array.length;i++){
- if(wert == array[i]){
- count++;
- }
- }
- System.out.println("Die Zahl "+wert +" ist "+count+" mal in Array vorhanden!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement