Advertisement
xArchitekt

Aufgabe 4.1

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