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.

Recommended Answers

All 4 Replies

Welcome!! First thing, post code in BB Tags. It's a good code.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.