-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElevator.java
More file actions
43 lines (32 loc) · 1.34 KB
/
Elevator.java
File metadata and controls
43 lines (32 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package Homework;
import java.util.Scanner;
public class Elevator {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Введите количесвто этажей в доме(H) : ");
int floorsValue = sc.nextInt();
System.out.println("Введите номер этажа, при подъеме на вверх(N): ");
int liftUp = sc.nextInt();
System.out.println("Введите номер этажа, при спуске вниз(M): ");
int liftDown = sc.nextInt();
System.out.println("H = " + floorsValue + ", N = " + liftUp + ", M = " + liftDown);
getCurrentFloor(floorsValue,liftUp,liftDown);
sc.close();
}
public static int getCurrentFloor(int h, int n, int m) {
if (h <= 1 || n <= m || n <= 1 || m < 0) {
System.out.println("Ошибка!");
return 0;
}
int currentFloor = 1;
for (int i = 1; i < h; i ++) {
if (h <= (i + n)) {
System.out.println("value of lift UP => " + currentFloor);
return currentFloor;
}
currentFloor++;
}
System.out.println("value of lift UP => " + currentFloor);
return currentFloor;
}
}