Java Program to Find Slope of a Line

bookmark

import java.io.*;
import java.util.*;
  
public class Main

    public static void main(String[] args) 
    { 
        //Scanner class object craeted
        Scanner sc=new Scanner(System.in);
        //points value are declared
        double x1 =4;
        System.out.println("value of x1:"+x1);
        double y1 =3;
        System.out.println("value of y1:"+y1);
        double x2 =2;
        System.out.println("value of x2:"+x2);
        double y2 =6;
        System.out.println("value of y2:"+y2);
        //Finding slope of line
        double slopeOfLine = (y2 - y1) / (x2 - x1); 
        //printing the result
        System.out.println("Slope of Line is : " +slopeOfLine ); 
    }
}

 


Output:

value of x1:4.0
value of y1:3.0
value of x2:2.0
value of y2:6.0
Slope of Line is : -1.5