Advertisement
Guest User

Übung9A1

a guest
Nov 27th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. public class U9A1
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         int[] x = {1,2,3,4,5,6};
  6.         int y = 4;
  7.        
  8.         System.out.println("gleiche Eintraege: " + aufgabea(x,y));
  9.         aufgabeb(x);
  10.         aufgabec(x);
  11.     }
  12.    
  13.     public static int aufgabea(int[] x, int y)
  14.     {
  15.         int gleich = 0;
  16.         for (int i=0; i<x.length; i++)
  17.         {
  18.             if(x[i]==y)
  19.             {
  20.                 gleich++;
  21.             }  
  22.         }
  23.         return gleich;
  24.     }
  25.    
  26.     public static void aufgabeb(int[] x)
  27.     {
  28.         int[] x1 = new int[x.length];
  29.         System.out.print("Rueckwaerts neues Feld: ");
  30.         for (int i = x.length - 1, j = 0; i >= 0; i--, j++)
  31.         {
  32.             x1[j] = x[i];
  33.             System.out.print(x1[j]);
  34.         }  
  35.         System.out.print("\n");
  36.     }
  37.    
  38.     public static void aufgabec(int[] x)
  39.     {
  40.         System.out.print("Rueckwaerts gleiches Feld: ");
  41.         for (int i = 0; i < x.length/2; i++)
  42.         {
  43.             int temp = x[i];
  44.             x[i] = x[x.length - i -1];
  45.             x[x.length - i - 1] = temp;
  46.             System.out.print(x[i]);  
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement