Line | |
---|
1 | import java.util.Scanner;
|
---|
2 |
|
---|
3 | public class SucheZahl {
|
---|
4 |
|
---|
5 | public static void main(String[] arg) {
|
---|
6 | int[][] arr = {{1, 2, 3},
|
---|
7 | {4, 5, 6, 7},
|
---|
8 | {8, 9, 10, 11, 12}};
|
---|
9 |
|
---|
10 | Scanner sc = new Scanner(System.in);
|
---|
11 | System.out.print("Geben Sie eine Zahl ein: ");
|
---|
12 | int zahl = sc.nextInt();
|
---|
13 | boolean gefunden = false;
|
---|
14 | int i = 0, j = 0;
|
---|
15 | suche: for (i=0; i<arr.length; i++) {
|
---|
16 | for (j=0; j<arr[i].length; j++) {
|
---|
17 | if (arr[i][j] == zahl) {
|
---|
18 | gefunden = true;
|
---|
19 | break suche;
|
---|
20 | }
|
---|
21 | }
|
---|
22 | }
|
---|
23 | if (gefunden)
|
---|
24 | System.out.println("Zahl " + zahl + " gefunden:" +
|
---|
25 | " arr[" + i + "][" + j + "]");
|
---|
26 | else
|
---|
27 | System.out.println("Zahl " + zahl +
|
---|
28 | " ist nicht gefunden");
|
---|
29 | }
|
---|
30 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.