Browse Source

Neue Testklassen

Ritter 2 năm trước cách đây
mục cha
commit
9f880f5e7b
3 tập tin đã thay đổi với 89 bổ sung0 xóa
  1. 13 0
      src/ArrayMerge.java
  2. 29 0
      src/CountA.java
  3. 47 0
      src/InputOutputArithMean.java

+ 13 - 0
src/ArrayMerge.java

@@ -0,0 +1,13 @@
+
+public class ArrayMerge {
+
+	public static void main(String[] args) {
+		// TODO Auto-generated method stub
+
+		int[] a = {4,8,1,6,3,8,7};
+		int[] b = {1,4,2,3,0};
+		
+		
+	}
+
+}

+ 29 - 0
src/CountA.java

@@ -0,0 +1,29 @@
+public class CountA {
+	public static int count_a(String str) {
+
+		// Verwenden Sie dafür nur eine for-Schleife und eine if-Abfrage
+		// Sie dürfen die Methoden length() und charAt(int i) der Klasse String verwenden 	
+		
+		int i = 0;
+		for (int j = 0; j < str.length(); j++) {
+			if ( str.charAt(j) == 'a' ) {
+				i++;
+			}
+			else {
+				
+			
+			}
+		}
+		return i;
+	}
+
+	public static void main(String[] args) {
+		assert (count_a("") == 0);
+		assert (count_a("a") == 1);
+		assert (count_a("aa") == 2);
+		assert (count_a("abb ") == 1);
+		assert (count_a(" abba ") == 2);
+		assert (count_a("bb") == 0);
+		System.out.println(" Everything good !");
+	}
+}

+ 47 - 0
src/InputOutputArithMean.java

@@ -0,0 +1,47 @@
+
+import java.util.Scanner;
+
+public class InputOutputArithMean {
+	
+	public static void main(String args[]) {
+		
+		Scanner scanner = new Scanner(System.in);
+		String s; 
+		int i = 0;
+		int m = 0;
+		
+		
+		while (i < 1) {
+			System.out.println("Bitte geben Sie die Anzahl der Zahlen ein, von denen Sie ein arithmetisches Mittel berechnen möchten:");
+			try
+			 {
+				i = scanner.nextInt();
+			 }
+			catch(Exception ex) {
+				System.out.println("Bitte überprüfen Sie ihre Eingabe");
+			}
+		}
+		
+		int[] arr = new int[i];
+		
+		for (int j = 0; j < i; j++) {
+			System.out.println("Bitte geben Sie die " + j + "te Zahl ein:");
+				try
+				{
+					/* arr[j] = scanner.nextInt(); */
+					m += scanner.nextInt();
+				}
+				catch(Exception ex) {
+					System.out.println("Bitte überprüfen Sie ihre Eingabe");
+				}
+			
+			
+		}
+		System.out.println("keine Konvertierung, hier ist das Ergebnis: " + m / i);
+		System.out.println(m / (double) i);
+		}
+		
+		
+	}
+
+