-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2947.java
More file actions
52 lines (44 loc) · 1.03 KB
/
2947.java
File metadata and controls
52 lines (44 loc) · 1.03 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
package algo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Task {
private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
private final int N = 5;
int[] numbers = new int[N];
public void input() throws IOException {
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
for(int i=0; i<N; i++) {
numbers[i] = Integer.parseInt(st.nextToken());
}
}
public void bubbleSort() {
for(int i=0; i<N; i++) {
for(int j=0; j<N-1; j++) {
if(numbers[j] > numbers[j+1]) {
int temp = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = temp;
print();
}
}
}
}
public void print() {
for(int i=0; i<N; i++) {
System.out.print(numbers[i] + " ");
}
System.out.println("");
}
public void run() throws IOException {
input();
bubbleSort();
}
}
public class main {
public static void main(String args[]) throws IOException {
Task task = new Task();
task.run();
}
}