输入两个点的坐标,即p1 = (x1, y1)和p2=(x2, y2),求过这两个点的直线的斜率。如果斜率为无穷大输出“INF”。
样例输入
1 2
2 4
样例输出
2
样例输入
1 2
1 4
样例输出
INF
样例输入
1 2
3 2
样例输出
0
import java.util.Scanner;
public class 斜率计算 {
public static void main(String[] args) {
Scanner sc =new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int d = sc.nextInt();
if(a==c){
System.out.println("INF");
}
else if(b==d){
System.out.println(0);
}
else{
int s1 = Math.abs(d-b);
int s2=Math.abs(c-a);
double result=s1/s2;
System.out.println(result);
}
}
}