-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArraysprac.java
More file actions
43 lines (40 loc) · 1.32 KB
/
Arraysprac.java
File metadata and controls
43 lines (40 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.Scanner;
public class Arraysprac {
public static void main(String[] args) {
// 1D arrays
Scanner sc = new Scanner(System.in);
// System.out.println("Enter the size of the array");
// int size = sc.nextInt();
// System.out.println("Enter the elements of the array");
// int[] arr = new int[size];
// for (int i = 0; i < size; i++) {
// arr[i] = sc.nextInt();
// }
// System.out.println("Enter the no to be searched");
// int x= sc.nextInt();
// for (int i = 0; i < size; i++) {
// if (arr[i]==x){
// System.out.println(i);
// }
// }
// 2d arrays practice
System.out.println("enter no of rows and columns respectively");
int rows = sc.nextInt();
int columns = sc.nextInt();
int [][] numbers = new int[rows][columns];
for(int i = 0;i<rows;i++){
for(int j = 0;j<columns;j++){
numbers[i][j] = sc.nextInt();
}
}
System.out.println("Enter the number to be searched");
int y = sc.nextInt();
for(int i = 0;i<rows;i++){
for(int j = 0;j<columns;j++){
if(numbers[i][j]==y) {
System.out.println(i+" "+ j);
}
}
}
}
}