Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class task7Lesson2 {
- public static void main(String[] args) {
- // Задача 1. Создайте массив из всех чётных чисел от 2 до 20 и выведите элементы
- // массива на экран сначала в строку,
- // отделяя один элемент от другого пробелом, а затем в столбик (отделяя один
- // элемент от другого началом новой строки).
- // Перед созданием массива подумайте, какого он будет размера.
- // 2 4 6 … 18 20
- // 2
- // 4
- // 6
- // …
- // 20
- int f = 0;
- int e = 0;
- int arr[] = new int[10];
- for (int i = 2; i <= 20; i++) {
- if (i % 2 == 0) {
- arr[f] = i;
- f++;
- }
- }
- int arr1[] = new int[10];
- for (int t = 2; t <= 20; t++) {
- if (t % 2 == 0) {
- arr1[e] = t;
- e++;
- }
- }
- for (int x = 0; x < arr.length; x++) {
- System.out.print(arr[x] + " ");
- }
- System.out.println();
- for (int r = 0; r < arr1.length + 1; r++) {
- System.out.println(arr1[r] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement