Hello Guys,

I'm considerably Newbie to any programming whatsoever, and i'm having to take Java for my computer Science requirement. I'm currently working on an homework assignment to write an application that reads the (X,Y) coordinates for two points. I also need to compute the distance between them using the following formula

distance = sqrt((X2-X1)^2 + (Y2-Y1)^2

So far, what i have is:

import java.util.Scanner;


//Reads the (X, Y) coordinates for two points



class Assignment2b{

public static void main (String[] args) {


Scanner scan = new Scanner (System.in);

System.out.print("Enter the value of X1 ");
System.out.flush();
int X1 = scan.nextInt;


System.out.print("Enter the value of X2 ");
System.out.flush();
int X2 = scan.nextInt;

System.out.print("Enter the value of Y1 ");
System.out.flush();
int Y1 = scan.nextInt;

System.out.print("Enter the value of Y2 ");
System.out.flush();
int Y2 = scan.nextInt;




double distance = Math.sqrt(Math.pow(X2-X1, 2) + Math.pow(Y2-Y1, 2));

System.out.println("The distance is" + distance);

    }
}

I'd appreciate any helpful insights.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

welcome to Java too :D
as i can see u have made good code so u dont need any help
good luck

Looks OK to me apart from nextInt being a method, and thus needing a pair of (). You should always try compiling before posting here, most Java error messages are pretty informative, and you should be able to fix many of the problems yourself.

Hi,

If you face any misconception, just use System.in.read() to read values from I/O and store it in BufferedReader Object and just continue your calculation.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.