1
Java Question.....Need Help?
Write the JAVA code for:
Find the slope s between any two given points: (x1,y1) and (x2,y2)
Find the slope s between any two given points: (x1,y1) and (x2,y2)
Choose another answer as the right one
/**
*
* @author Sherwin Roy
* Davao del Norte State College
*/
import java.util.Scanner;
public class Slope {
public static void main (String []args){
Scanner input=new Scanner(System.in);
System.out.println("Enter the x1:");
double x1=input.nextDouble();
System.out.println("Enter the y1:");
double y1=input.nextDouble();
System.out.println("Enter the x2:");
double x2=input.nextDouble();
System.out.println("Enter the y2:");
double y2=input.nextDouble();
double slope=(y1-y2)/(x1-x2);
System.out.println("The slope is "+slope);
}
}
Choose another answer as the right one
public class Slope
{
public static void main(String args[])
{
int x1,y1,x2,y2;
float m;
Scanner inp=new Scanner(System.in);
System.out.println("\n x1: ");
x1=inp.nextInt();
System.out.println(" y1: ");
y1=inp.nextInt();
System.out.println("\n x2: ");
x2=inp.nextInt();
System.out.println("\n y2: ");
y2=inp.nextInt();
m=((float)(x2-x1))/(y2-y1);
System.out.println("\n\n\n Slope is "+m);
}
}
Choose another answer as the right one