File tree Expand file tree Collapse file tree 9 files changed +164
-0
lines changed
src/main/java/ru/mirea/practice/s23k0087 Expand file tree Collapse file tree 9 files changed +164
-0
lines changed Original file line number Diff line number Diff line change 4444 <module >students/23K0364</module >
4545 <module >students/23K0155</module >
4646 <module >students/23K0114</module >
47+ <module >students/23K0087</module >
4748 <module >students/23K0112</module >
4849 <module >students/23K0351</module >
4950 <module >students/23K0563</module >
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
4+ <modelVersion >4.0.0</modelVersion >
5+ <parent >
6+ <artifactId >23K0087</artifactId >
7+ <groupId >ru.mirea.practice</groupId >
8+ <version >2024.1</version >
9+ <relativePath >../pom.xml</relativePath >
10+ </parent >
11+ <artifactId >23K0087-p01</artifactId >
12+ <description >Массивы</description >
13+ </project >
Original file line number Diff line number Diff line change 1+ package ru .mirea .practice .s23k0087 ;
2+
3+ import java .util .Arrays ;
4+ import java .util .Scanner ;
5+
6+
7+ public abstract class Task3 {
8+ public static void main (String [] args ) {
9+ int n ;
10+ int [] mas ;
11+ try (Scanner sc = new Scanner (System .in )) {
12+ System .out .print ("Введите количество элементов массива > " );
13+ n = sc .nextInt ();
14+ mas = new int [n ];
15+
16+ for (int i = 0 ; i < mas .length ; i ++) {
17+ System .out .print ("Введите " + (i + 1 ) + " элемент массива > " );
18+ mas [i ] = sc .nextInt ();
19+ System .out .print ("\033 [H\033 [2J" );
20+ }
21+ }
22+ System .out .println (Arrays .toString (mas ));
23+ int sum = 0 ;
24+
25+ for (int ma : mas ) {
26+ sum += ma ;
27+ }
28+
29+ System .out .println ("Сумма всех элементов массива: " + sum );
30+ float mean = (float ) sum / mas .length ;
31+ System .out .println ("Среднее арифметическое всех чисел массива: " + mean );
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ package ru .mirea .practice .s23k0087 ;
2+
3+ import java .util .Scanner ;
4+
5+ public abstract class Task4 {
6+ public static void main (String [] args ) {
7+ int n ;
8+ int [] mas ;
9+ try (Scanner sc = new Scanner (System .in )) {
10+ System .out .print ("Введите количество элементов массива > " );
11+ n = sc .nextInt ();
12+ mas = new int [n ];
13+ if (n <= 0 ) {
14+ System .out .println ("Количество элементов массива не должно быть меньше 1" );
15+ sc .close ();
16+ return ;
17+ }
18+ for (int i = 0 ; i < mas .length ; i ++) {
19+ System .out .print ("Введите " + (i + 1 ) + " элемент массива > " );
20+ mas [i ] = sc .nextInt ();
21+ System .out .print ("\033 [H\033 [2J" );
22+ }
23+ } catch (RuntimeException e ) {
24+ throw new RuntimeException (e );
25+ }
26+ int j = 0 ;
27+ int sum = 0 ;
28+ do {
29+ sum += mas [j ];
30+ j ++;
31+ } while (j < mas .length );
32+ System .out .println (sum );
33+ sum = 0 ;
34+ j = 0 ;
35+ while (j < mas .length ) {
36+ sum += mas [j ];
37+ j ++;
38+ }
39+ System .out .println (sum );
40+ int min = mas [0 ];
41+ for (int ma : mas ) {
42+ if (min > ma ) {
43+ min = ma ;
44+ }
45+ }
46+ System .out .println ("Минимальный элемент массива: " + min );
47+ int max = mas [0 ];
48+ for (int ma : mas ) {
49+ if (max < ma ) {
50+ max = ma ;
51+ }
52+ }
53+ System .out .println ("Максимальный элемент массива: " + max );
54+ }
55+ }
Original file line number Diff line number Diff line change 1+ package ru .mirea .practice .s23k0087 ;
2+
3+ public abstract class Task5 {
4+ public static void main (String [] args ) {
5+ for (String arg : args ) {
6+ System .out .println (arg );
7+ }
8+ }
9+ }
Original file line number Diff line number Diff line change 1+ package ru .mirea .practice .s23k0087 ;
2+
3+ public abstract class Task6 {
4+ public static void main (String [] args ) {
5+ System .out .println ("Первые 10 чисел гармонического ряда:" );
6+ for (int i = 1 ; i <= 10 ; i ++) {
7+ System .out .printf ("1/%d = %.4f%n" , i , 1.0 / i );
8+ }
9+ }
10+
11+ }
Original file line number Diff line number Diff line change 1+ package ru .mirea .practice .s23k0087 ;
2+
3+ public abstract class Task7 {
4+ public static long factorial (int n ) {
5+ if (n < 0 ) {
6+ throw new IllegalArgumentException ("Факториал отрицательного числа не определен" );
7+ }
8+ long result = 1 ;
9+ for (int i = 1 ; i <= n ; i ++) {
10+ result *= i ;
11+ }
12+ return result ;
13+ }
14+
15+ public static void main (String [] args ) {
16+ int [] testNumbers = {0 , 5 , 10 , -10 };
17+ for (int testNumber : testNumbers ) {
18+ System .out .println ("Факториал " + testNumber + " = " + factorial (testNumber ));
19+ }
20+ }
21+ }
22+
Original file line number Diff line number Diff line change 1+ Абсулов Даниил
2+ КВБО-01-23
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <project xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xmlns =" http://maven.apache.org/POM/4.0.0"
3+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
4+ <modelVersion >4.0.0</modelVersion >
5+ <parent >
6+ <artifactId >algorithms-and-data-structures</artifactId >
7+ <groupId >ru.mirea.practice</groupId >
8+ <version >2024.1</version >
9+ <relativePath >../../pom.xml</relativePath >
10+ </parent >
11+ <artifactId >23K0087</artifactId >
12+ <packaging >pom</packaging >
13+ <description >Практическая работа Даниила</description >
14+
15+ <modules >
16+ <module >23K0087-p01</module >
17+ </modules >
18+ </project >
You can’t perform that action at this time.
0 commit comments