From 80de92fa1eaa4b54b829f72c1682c2523f808618 Mon Sep 17 00:00:00 2001 From: Rhinemann <72938564+Rhinemann@users.noreply.github.com> Date: Wed, 22 Mar 2023 17:02:31 +0200 Subject: [PATCH] Lab 1 commit --- Lab 1/Lab_1.java | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Lab 1/Lab_1.java diff --git a/Lab 1/Lab_1.java b/Lab 1/Lab_1.java new file mode 100644 index 0000000..8217562 --- /dev/null +++ b/Lab 1/Lab_1.java @@ -0,0 +1,39 @@ +import java.util.Scanner; + +public class Lab_1 { + public static void main(String[] args) { + int n, m, a, b; + float s = 0; + + Scanner input = new Scanner(System.in); + + System.out.print("Enter n: "); + n = input.nextInt(); + + System.out.print("Enter m: "); + m = input.nextInt(); + + do { + System.out.print("Enter a (can't be above n): "); + a = input.nextInt(); + } while (a > n); + + do { + System.out.print("Enter b (can't be above m): "); + b = input.nextInt(); + } while (b > m); + + if ((a <= 0) && (n >= 0)) { + System.out.println("Error, division by zero, shutting down!"); + System.exit(1); + } + + for (int i = a; i < n; i++) { + for (int j = b; j < m; j++) { + s += i * j / i; + } + } + + System.out.println("S = " + s); + } +}