자바질문인데요. 이 프로그램에서 어디가 에러나는지 어떻게 찾나요??
한내
import java.util.*; //?
import java.util.Scanner; //?
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println(Input x coordinate for the first point.); // two private instance가져야한다는게 무슨뜻???
float x = s.nextFloat(); // x 초기화로 0 해줘야하나 ?
System.out.println(Input y coordinate for the first point.);
float y = s.nextFloat();
System.out.println(Input z coordinate for the first point.);
float z = s.nextFloat();
System.out.println(Input x coordinate for the second point.);
float j = s.nextFloat(); // x 초기화로 0 해줘야하나 ?
System.out.println(Input y coordinate for the second point.);
float q = s.nextFloat();
System.out.println(Input z coordinate for the second point.);
float k = s.nextFloat();
System.out.println(Two endpoints of line segment are + ( + x + , + y + , + z + ) + and + ( + j + , + q + , + k + ).);
linesegment(x, y, z, j, q, k);
}
static void linesegment(float x, float y, float z, float j, float q, float k)
{
float xcoor = (x - j) * (x - j);
float ycoor = (y - q) * (y - q);
float zcoor = (z - k) * (z - k);
float result = Math.sqrt(xcoor + ycoor + zcoor);
System.out.println(The distance between two endpoints is + result + .);
}
}
위는 제가 만든건데요. run해보니까 error있다네요;;;
error가 뭔지 좀 알려주세요-_ㅠ 아 그리고 어떤부분에서 error가 나는지 알아보는 방법은 없나요?
c++할때는 debug로 해서 어떻게 했던거 같은데...
-
도도
Math.sqrt 가 리턴하는 것이 double 인데 float 로 받아서 나는 에러입니다.
그리고 이클립스 쓰면 다 나오는데 안쓰시는 모양이네요. ??
요즘 자바도 IDE 툴둘이 많아서 괜찮습니다.. -
흰가람
에러는 콘솔에 나오져.
에러는
float result = (float) Math.sqrt(xcoor + ycoor + zcoor);이거네요. 형변환을 해줘야죠
전 1.4라 Scanner를 못쓰네 ㅠ