Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/ru/skypro/Main.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
package ru.skypro;

import java.util.Arrays;

public class Main {
//Входные данные
public static int[] generateRandomArray() {
java.util.Random random = new java.util.Random();
int[] arr = new int[30];
for (int i = 0; i < arr.length; i++) {
arr[i] = random.nextInt(100_000) + 100_000;
}
return arr;
}
public static void main(String[] args){

int[] arr = generateRandomArray();

// Задание 1
int sum=0;
for (int i : arr) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

здесь лучше назвать переменную более осознанно, т.к. обычно i называют индексы массива, а здесь уже не индекс, а элемент

sum+=i;
}
System.out.println("Сумма трат за месяц составила "+sum+" рублей");

// Задание 2
int min = 0,max=0;
for (int i : arr) {
if (min ==0 || min > i)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

фигурные скобки надо ставить

min = i;
if (max ==0 || max < i)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

фигурные скобки надо ставить

max = i;
}
System.out.println("Минимальная сумма трат за день составила "+min+" рублей. " +
"Максимальная сумма трат за день составила "+max+" рублей");

// Задание 3
double avgMonth = sum/(double) arr.length;
System.out.println("Средняя сумма трат за месяц составила "+avgMonth+" рублей");

// Задание 4
char[] reverseFullName = { 'n', 'a', 'v', 'I', ' ', 'v', 'o', 'n', 'a', 'v', 'I'};

for (int j = reverseFullName.length - 1; j >= 0; j--) {
System.out.print(reverseFullName[j]);
}
}
}