解题思路:知道直线方程y=kx+b,那么k就是斜率如果不知道直线方程,
* 但知道直线上的两个点(x1,y1),(x2,y2)
* 那么斜率k=(y2-y1)/(x2-x1)如果x1=x2,
* 那么直线斜率不存在。
注意事项:
参考代码:import java.util.Scanner;
public class Main4 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
* 输入两个点的坐标,即p1 = (x1, y1)和p2=(x2, y2),
* 求过这两个点的直线的斜率。如果斜率为无穷大输出“INF”。
* */
Scanner scanner=new Scanner(System.in);
int [] a=new int[2];
int [] b=new int[2];
for (int i = 0; i
a[i]=scanner.nextInt();
}
for (int i = 0; i
b[i]=scanner.nextInt();
}
if (a[0]==b[0]) {
System.out.println("INF");
}else {
System.out.println((b[1]-a[1])/(b[0]-a[0]));
}
}
}