I'm trying to create a program that receives user input for x2, x1, y2, y1 variables to calculate slope. Here's what I've got so far, can't figure out how to display undefined with error coming up...
import java.util.Scanner; public class SlopeIntercept { public static void main(String[] args) { int x1; int y1; int x2; int y2; double slope; double undefined; double yIntercept; double xIntercept; Scanner userInput = new Scanner(System.in); System.out.print("Enter the X and Y coordinates of starting point:"); System.out.print("\n\tx1" + " = "); x1 = userInput.nextInt(); System.out.print("\ty1" + " = "); y1 = userInput.nextInt(); System.out.print("Enter the X and Y coordinates of ending point:"); System.out.print("\n\tx2" + " = "); x2 = userInput.nextInt(); System.out.print("\ty2" + " = "); y2 = userInput.nextInt(); System.out.print("Slope:" + slope); if (x2 == x1); { System.out.print("Slope: undefined"); } yIntercept = y1 - (slope * x1); yIntercept = y2 - (slope * x2); System.out.print(yIntercept); xIntercept = -1 * (yIntercept / slope); System.out.print(xIntercept); } }