-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayUtility.java
More file actions
56 lines (43 loc) · 1.68 KB
/
Copy pathArrayUtility.java
File metadata and controls
56 lines (43 loc) · 1.68 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
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.Scanner;
public class ArrayUtility {
public static int[] inputArray(){
Scanner in = new Scanner(System.in);
System.out.print("Please Enter the number of Element: ");
int size = in.nextInt();// getting input from the user
int[] nums = new int[size]; // Create a new array to decalre the size of an array
int i = 0;
while (i < size) {
System.out.print("Please enter the element no." + (i+1) + ": ");
nums[i] = in.nextInt();//iterate the nput of a number from the user
i++;
}
return nums;
}
public static int[][] input2DArray(){
Scanner in = new Scanner(System.in);
System.out.print("Please Enter the number of rows: ");
int rows = in.nextInt();// getting input from the user
System.out.print("Please Enter the number of columns: ");
int columns = in.nextInt();// getting input from the user
int[][] numArray = new int[rows][columns]; // Create a new array to decalre the size of an array
int i = 0;
while (i < rows) {
int j = 0;
while(j < columns){
System.out.print("Please enter the rows no." + (i+1) + ", columns: "+ (j+1) + " :");
numArray[i][j] = in.nextInt(); //iterate the nput of a number from the user
j++;
}
i++;
}
return numArray;
}
public static void displayArray(int[] numArr){
int i = 0;
while(i < numArr.length){
System.out.println(numArr[i] + " ");
i++;
}
System.out.println();
}
}