Program to find slope of a line | Java program for slope of line ; function to find the slope of a straight line ; driver code to check the above function
import java . util . * ; class GFG { static float slope ( float x1 , float y1 , float x2 , float y2 ) { if ( x1 == x2 ) return Integer . MAX_VALUE ; return ( y2 - y1 ) / ( x2 - x1 ) ; } public static void main ( String [ ] args ) { float x1 = 4 , y1 = 2 ; float x2 = 2 , y2 = 5 ; System . out . print ( " Slope ▁ is : ▁ " + slope ( x1 , y1 , x2 , y2 ) ) ; } }