我有 2 个用户需要输入的 int 变量,我需要找到它们差异的绝对值,有没有办法按照我在这段代码中开始的相同原理来做到这一点?
Scanner scn = new Scanner(System.in);
int yourfloor, elefloor, desfloor;`enter code here`
System.out.println("Please enter your current floor");
yourfloor = scn.nextInt();
System.out.println("Please enter the elevator current floor(before inviting)");
elefloor = scn.nextInt();
System.out.println("Please enter your destination floor");
desfloor = scn.nextInt();
int getTime = yourfloor - elefloor;
if (getTime<0);
{getTime*(-1)};