Lab 1 commit

This commit is contained in:
Rhinemann 2023-03-22 17:02:31 +02:00 committed by GitHub
parent 14c58d0cc4
commit 80de92fa1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 0 deletions

39
Lab 1/Lab_1.java Normal file
View File

@ -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);
}
}