-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInpArray.java
More file actions
27 lines (21 loc) · 828 Bytes
/
Copy pathUserInpArray.java
File metadata and controls
27 lines (21 loc) · 828 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
26
27
import java.util.Scanner;
public class UserInputArray {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter size of the array: ");
int size = scanner.nextInt(); // Array ka size
int[] numbers = new int[size]; // Array banaya
// Array ke elements user se input lena
System.out.println("Enter " + size + " numbers:");
for (int i = 0; i < size; i++) {
System.out.print("Element " + (i + 1) + ": ");
numbers[i] = scanner.nextInt();
}
// Array ke elements print karna
System.out.println("You entered:");
for (int i = 0; i < size; i++) {
System.out.println("Element " + (i + 1) + ": " + numbers[i]);
}
scanner.close();
}
}