Update Lab 1.

This commit is contained in:
Rhinemann 2023-05-02 09:58:31 +03:00
parent 896fc1f4d4
commit fe36219746
1 changed files with 42 additions and 19 deletions

View File

@ -7,32 +7,55 @@ public class Lab_1 {
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
do {
try {
System.out.print("Enter n: "); System.out.print("Enter n: ");
n = input.nextInt(); n = input.nextInt();
break;
} catch (Exception e) {
System.out.println("N must be an integer.");
input.nextLine();
}
} while (true);
do {
try {
System.out.print("Enter m: "); System.out.print("Enter m: ");
m = input.nextInt(); m = input.nextInt();
break;
} catch (Exception e) {
System.out.println("M must be an integer.");
input.nextLine();
}
} while (true);
do { do {
System.out.print("Enter a (can't be above n): "); try {
System.out.print("Enter a: ");
a = input.nextInt(); a = input.nextInt();
} while (a > n); break;
} catch (Exception e) {
System.out.println("A must be an integer.");
input.nextLine();
}
} while (true);
do { do {
System.out.print("Enter b (can't be above m): "); try {
System.out.print("Enter b: ");
b = input.nextInt(); b = input.nextInt();
} while (b > m); break;
} catch (Exception e) {
System.out.println("B must be an integer.");
input.nextLine();
}
} while (true);
input.close(); input.close();
if ((a <= 0) && (n >= 0)) { for (int i = a; i <= n; i++) {
System.out.println("Error, division by zero, shutting down!"); for (int j = b; j <= m; j++) {
System.exit(1); s += j;
}
for (int i = a; i < n; i++) {
for (int j = b; j < m; j++) {
s += i * j / i;
} }
} }