forked from FatimaAlazazi/DataStructure2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputEX.java
More file actions
43 lines (36 loc) · 1.04 KB
/
InputEX.java
File metadata and controls
43 lines (36 loc) · 1.04 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
package Week1;
import java.util.Scanner;
public class InputEX {
static int[] a = new int[6];
static Scanner in = new Scanner(System.in);
static int numOfElements=0;
static public void InputElements(int x)
{
if(numOfElements<a.length){
a[numOfElements]=x;
numOfElements++;
}
else
System.out.println("Sorry , The Array is full");
}
static public void Print()
{
System.out.print("[ ");
for (int i = 0; i <a.length ; i++) {
if(i==a.length-1)
System.out.print(a[i]+" ]");
else
System.out.print(a[i]+" , ");
}
}
public static void main(String[] args) {
int x;
System.out.println("Enter The Elements :");
for (int i = 0; i <a.length ; i++) {
x=in.nextInt();
InputElements(x);
}
////////////////////////////////////////////////
Print();
}
}