Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit 5319834

Browse files
authored
Merge pull request #692 from Phonggg1410/Features/lab1-32
Hoang Xuan Phong/ lab 1-32
2 parents d4f4c76 + 32f7909 commit 5319834

File tree

245 files changed

+9184
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

245 files changed

+9184
-0
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<module>students/23K0186</module>
8282
<module>students/23K0755</module>
8383
<module>students/23K1292</module>
84+
<module>students/23L0908</module>
8485
</modules>
8586
<dependencies>
8687
<dependency>

students/23L0908/23L0908-p01/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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>23L0908</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23L0908-p01</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package ru.mirea.practice.s23l0908;
2+
3+
import java.util.Scanner;
4+
5+
public final class Task3 {
6+
private Task3() {
7+
}
8+
9+
public static void main(String[] args) {
10+
try (Scanner scanner = new Scanner(System.in)) {
11+
System.out.print("Enter n: ");
12+
int n = scanner.nextInt();
13+
int[] arr = new int[n];
14+
int sum = 0;
15+
for (int i = 0; i < n; i++) {
16+
System.out.print("arr[" + (i + 1) + "] = ");
17+
arr[i] = scanner.nextInt();
18+
}
19+
for (int i = 0; i < n; i++) {
20+
sum += arr[i];
21+
}
22+
double average = (double) sum / n;
23+
System.out.println("Sum: " + sum);
24+
System.out.println("Average: " + average);
25+
}
26+
}
27+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package ru.mirea.practice.s23l0908;
2+
3+
import java.util.Scanner;
4+
5+
public final class Task4 {
6+
7+
private Task4() {
8+
}
9+
10+
public static void main(String[] args) {
11+
try (Scanner scanner = new Scanner(System.in)) {
12+
System.out.print("Enter n: ");
13+
int n = scanner.nextInt();
14+
int[] arr = new int[n];
15+
int i = 0;
16+
int sum = 0;
17+
do {
18+
System.out.print("arr[" + i + "] = ");
19+
arr[i] = scanner.nextInt();
20+
sum += arr[i];
21+
i++;
22+
} while (i < n);
23+
24+
i = 0;
25+
int min = arr[0];
26+
int max = arr[0];
27+
while (i < n) {
28+
if (arr[i] < min) {
29+
min = arr[i];
30+
}
31+
if (arr[i] > max) {
32+
max = arr[i];
33+
}
34+
i++;
35+
}
36+
37+
System.out.println("Sum = " + sum);
38+
System.out.println("Min = " + min);
39+
System.out.println("Max = " + max);
40+
}
41+
}
42+
}
43+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ru.mirea.practice.s23l0908;
2+
3+
public final class Task5 {
4+
5+
private Task5() {
6+
}
7+
8+
public static void main(String[] args) {
9+
if (args.length > 0) {
10+
System.out.println("Doi so dong lenh duoc truyen vao:");
11+
for (int i = 0; i < args.length; i++) {
12+
System.out.println("Doi so " + i + " = " + args[i]);
13+
}
14+
} else {
15+
System.out.println("Doi so khong duoc truyen");
16+
}
17+
}
18+
}
19+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package ru.mirea.practice.s23l0908;
2+
3+
public final class Task6 {
4+
5+
private Task6() {
6+
// Private constructor to prevent instantiation
7+
}
8+
9+
public static void main(String[] args) {
10+
int n = 10;
11+
double sum = 0.0;
12+
System.out.println("10 number:");
13+
for (int i = 1; i <= n; i++) {
14+
sum += 1.0 / i;
15+
System.out.printf("H%d = %.4f%n", i, sum);
16+
}
17+
System.out.println("Result: " + sum);
18+
}
19+
}
20+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package ru.mirea.practice.s23l0908;
2+
3+
import java.util.Scanner;
4+
5+
public final class Task7 {
6+
7+
private Task7() {
8+
// Private constructor to prevent instantiation
9+
}
10+
11+
public static void main(String[] args) {
12+
try (Scanner scanner = new Scanner(System.in)) {
13+
System.out.println("Enter n: ");
14+
int n = scanner.nextInt();
15+
long result = giaithua(n);
16+
System.out.print("Result: " + result);
17+
}
18+
}
19+
20+
public static long giaithua(int n) {
21+
if (n < 0) {
22+
System.out.println("Cannot calculate factorial for negative numbers!");
23+
return -1;
24+
} else {
25+
long fact = 1;
26+
for (int i = 1; i <= n; i++) {
27+
fact *= i;
28+
}
29+
return fact;
30+
}
31+
}
32+
}
33+

students/23L0908/23L0908-p02/pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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>23L0908</artifactId>
7+
<groupId>ru.mirea.practice</groupId>
8+
<version>2024.1</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<artifactId>23L0908-p02</artifactId>
12+
<description>Массивы</description>
13+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package ru.mirea.practice.s23l0908;
2+
3+
public class Ball {
4+
private float x;
5+
private float y;
6+
private float xspeed;
7+
private float yspeed;
8+
9+
@SuppressWarnings("unused")
10+
public Ball() {
11+
this.x = 0.0f;
12+
this.y = 0.0f;
13+
this.xspeed = 1.0f;
14+
this.yspeed = 1.0f;
15+
}
16+
17+
public Ball(float x, float y, float xspeed, float yspeed) {
18+
this.x = x;
19+
this.y = y;
20+
this.xspeed = xspeed;
21+
this.yspeed = yspeed;
22+
}
23+
24+
public void move() {
25+
x += xspeed;
26+
y += yspeed;
27+
}
28+
29+
public void reverse() {
30+
xspeed = -xspeed;
31+
yspeed = -yspeed;
32+
}
33+
34+
public String toString() {
35+
return "Ball {"
36+
+ "x= " + x
37+
+ ", y= " + y
38+
+ ",xSpeed=" + xspeed
39+
+ ",ySpeed=" + yspeed
40+
+ "}";
41+
}
42+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ru.mirea.practice.s23l0908;
2+
3+
public final class Testball {
4+
5+
private Testball() {
6+
7+
}
8+
9+
public static void main(String[] args) {
10+
Ball ball = new Ball(0, 0, 4, 6);
11+
System.out.println("Begin: " + ball);
12+
ball.move();
13+
System.out.println("After move: " + ball);
14+
ball.reverse();
15+
ball.move();
16+
System.out.println("After reverse move: " + ball);
17+
}
18+
}
19+

0 commit comments

Comments
 (0)