-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask2.java
More file actions
42 lines (31 loc) · 1.05 KB
/
Copy pathTask2.java
File metadata and controls
42 lines (31 loc) · 1.05 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
package HomeWork;
import java.util.Scanner;
/**
* Created by lelyi4ka on 02.06.15.
*/
public class Task2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Введите длину массива");
try {
int n = in.nextInt();
int[] arrN = new int[n];
for (int i = 0; i < n; i++) {
arrN[i] = i; // заполняем массив числами от 0 до n
}
System.out.println("Исходный массив чисел: ");
for (int element : arrN) {
System.out.println(element);
}
int k = arrN[n-1];
arrN[n-1] = arrN[0];
arrN[0] = k;
System.out.println("Итоговый массив чисел: ");
for (int element : arrN) {
System.out.println(element);
}
}catch (Exception e){
System.out.println("неправильный ввод");
}
}
}