From 4417dfe95aff9bfb8e90e3ea22623d2ef6f1f6f4 Mon Sep 17 00:00:00 2001 From: Oleh Date: Mon, 20 Mar 2023 17:36:00 +0100 Subject: [PATCH] add lab1 --- .idea/misc.xml | 2 +- src/lab1.java | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/lab1.java diff --git a/.idea/misc.xml b/.idea/misc.xml index d15472f..7464918 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/src/lab1.java b/src/lab1.java new file mode 100644 index 0000000..a8f7181 --- /dev/null +++ b/src/lab1.java @@ -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); + + } +}