1 import java.util.Scanner;
2 import java.util.Random;
3
4 public class liftvezerlo {
5 public static void main(String args[]) {
6
7 Random veletlen = new Random();
8 int aktualis = veletlen.nextInt(11);
9 int cel = veletlen.nextInt(11);
10 char irany;
11 if (aktualis < cel) {
12 irany = 'F';
13 }
14 else if (aktualis > cel) {
15 irany = 'L';
16 }
17 else {
18 irany = '-';
19 }
20
21 System.out.printf("A lift helyzete: %d %c (%d)%n", aktualis, irany, cel);
22
23
24 System.out.print("Adja meg a szintet, ahonnan hivja a liftet! Szint: ");
25 Scanner scanner = new Scanner(System.in);
26 int hivo = scanner.nextInt();
27
28
29 int megtett = 0;
30 if (Math.min(aktualis, cel) <= hivo && hivo <= Math.max(aktualis, cel))
31
32 megtett = Math.abs(aktualis - hivo);
33 else
34
35
36 megtett = Math.abs(aktualis - cel) + Math.abs(cel - hivo);
37
38 System.out.printf("A liftnek %d emeletet kell haladnia a hivoig.%n", megtett);
39 }
40 }
41