Computer Science, asked by vishva5000, 7 months ago

the coordinates of 2 points a and b on straight line are given (x1,y2) and (x2,y2). write a program to calculate the slope (m) of the line by using formula: Slope=(y2-y1)/(x2-x1) take coordinates(x1,y1) and (x2,y2) as input

Answers

Answered by alanparackalsebastia
4

Answer:

import java.util.Scanner;

public class Slope

{

   public static void main(String args[]) {

       

       Scanner in = new Scanner(System.in);

       

       System.out.print("Enter x coordinate of point A: ");

       int x1 = in.nextInt();

       

       System.out.print("Enter y coordinate of point A: ");

       int y1 = in.nextInt();

       

       System.out.print("Enter x coordinate of point B: ");

       int x2 = in.nextInt();

       

       System.out.print("Enter y coordinate of point B: ");

       int y2 = in.nextInt();

       

       float lineSlope = (y2 - y1) / (float)(x2 - x1);

       

       System.out.println("Slope of line: " + lineSlope);

Explanation:

Think it will help,ThankYou

Similar questions