This commit is contained in:
Oleh 2023-03-20 17:36:00 +01:00
parent 14c58d0cc4
commit 4417dfe95a
2 changed files with 46 additions and 1 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="openjdk-18" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

45
src/lab1.java Normal file
View File

@ -0,0 +1,45 @@
import java.util.Scanner;
public class lab1 {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
// 2131 % 7 = 3; C7 = long
long n, m, a, b;
float result, sum;
while(true) {
try {
System.out.println("Введіть n типу long:");
n = scanner.nextLong();
System.out.println("Введіть m типу long:");
m = scanner.nextLong();
System.out.println("Введіть a типу long:");
a = scanner.nextLong();
System.out.println("Введіть b типу long:");
b = scanner.nextLong();
break;
}catch(Exception e){
scanner.nextLine();
System.out.println("Введене неправильне число");
}
}
// 2131 % 5 = 1; O2 = /
// 2131 % 2 = 1; O1 = -
// 2131 % 3 = 1; C = 1
result = 0;
byte C = 1;
for(long i = a; i <= n; i++){
sum = 0;
for(long j = b; j <= m; j++){
if (i - C == 0 || j == 0){
System.out.println("Помилка ділення на 0");
System.exit(0);
}
sum += (float) (i/j)/(i-C);
}
result += sum;
}
System.out.println(result);
}
}