-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser_input_Array.java
More file actions
25 lines (23 loc) · 845 Bytes
/
User_input_Array.java
File metadata and controls
25 lines (23 loc) · 845 Bytes
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
import java.util.Scanner;
public class User_input_Array {
public static void main(String[] args) {
System.out.print("Enter the lenght of array for generating: ");
Scanner input = new Scanner(System.in);
int length = input.nextInt();
int arr[] = new int[length];
System.out.println("The lenght of the array: "+ arr.length);
System.out.println("Enter values: ");
// Getting the values into the array:
for (int i = 0; i < length; i++){
arr[i] = input.nextInt();
}
System.out.print("Array created= ");
System.out.print("{");
for (int j = 0; j < length; j++){
System.out.print(arr[j]);
if (j < arr.length-1) System.out.print(",");
else break;
}
System.out.print("}");
}
}