-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyClass.java
More file actions
61 lines (46 loc) · 1.59 KB
/
Copy pathMyClass.java
File metadata and controls
61 lines (46 loc) · 1.59 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
57
58
59
60
61
import java.io.IOException;
import java.util.Scanner;
public class MyClass {
public static void main(String[] args) throws IOException {
int lengthOfArr = 5;
int[] arr = new int[lengthOfArr];
System.out.println("Please, enter numbers for array: ");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
int count = 0;
if (input.length() != 0) {
count++;
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) == ' ') {
count++;
}
}
}
System.out.println("Entered " + count + " numbers");
if (lengthOfArr < count) {
do {
lengthOfArr = lengthOfArr * 2;
} while (lengthOfArr < count);
arr = new int[lengthOfArr];
}
System.out.print("Length of Array " + lengthOfArr);
System.out.println();
String[] arrOfInput = input.split(" ");
for (int i = 0; i < count; i++) {
arr[i] = Integer.parseInt(arrOfInput[i]);
}
System.out.println();
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println("Please, enter simbol for delete: ");
Scanner s= new Scanner(System.in);
int x = s.nextInt();
for(int i=0;i<arr.length; i++){
if(arr[i] == x){
arr[i] = 0;
}
System.out.print(arr[i] + " ");
}
}
}