good luck~~


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :이지연 2000년 5월 18일 09:36:36

In Reply to: 고쳐서 했는데 또 안돼요.제발 다시봐주세요. posted by 제발 답변주세요. on 2000년 5월 18일 00:52:22:

import java.io.*;


class Triangle {


//////////////////////////////////////////////////////////
//Triangle_control tri1 = new Triangle_control();
//////////////////////////////////////////////////////////


public static void main (String[] args) throws IOException {


Triangle_control tri1 = new Triangle_control();
int line1, line2, line3;
BufferedReader stdin = new BufferedReader
(new InputStreamReader (System.in));



//세 변을 입력받는다.
System.out.println ("삼각형의 세 변을 입력하시오.");
System.out.println ("line1 :");
line1 = Integer.parseInt(stdin.readLine());
System.out.println ("line2 :");
line2 = Integer.parseInt(stdin.readLine());
System.out.println ("line3 :");
line3 = Integer.parseInt(stdin.readLine());


//삼각형의 타입을 결정한다.
if (tri1.is_right( line1, line2, line3))
System.out.println ("직각 삼각형입니다.");
//////////////////////////////////////////////////////////
//if (tri1.is_scalene( line1, line2, line3))
if (tri1.is_scanlene( line1, line2, line3))
//////////////////////////////////////////////////////////
System.out.println ("두변의 길이가 모두 다르다.");
if (tri1.is_isosceles( line1, line2, line3))
System.out.println ("정확히 두 변의 길이가 같다.");
if (tri1.is_equilateral( line1, line2, line3))
//////////////////////////////////////////////////////////
//system.out.println ("세 변의 길이가 모두 같다.");
System.out.println ("세 변의 길이가 모두 같다.");
//////////////////////////////////////////////////////////
}//클래스 Triangle



//삼각형의 타입 조건을 설정해준다.
//////////////////////////////////////////////////////////
//class Triangle_control {
static class Triangle_control {
//////////////////////////////////////////////////////////


int l1,l2,l3;


public boolean is_right(int line1,int line2,int line3){
boolean success = false;
//////////////////////////////////////////////////////////
l1=l2=l3=0;
//////////////////////////////////////////////////////////


if (line1 > line2) { l3 = line1; l1 = line2;}
else { l3 = line2; l1 = line1; }


//////////////////////////////////////////////////////////
// if (line3 > line3a) { l2 = line3a; l3 = line3; }
if (line3 > line1) { l2 = line1; l3 = line3; }
//////////////////////////////////////////////////////////
else { l2 = line3; }


if ((l3*l3) == (l2*l2 + l1*l1))
success = true;
return success;
}//직각 삼각형


public boolean is_scanlene(int line1,int line2,int line3) {
boolean success = false;
if ((line1 != line2) && (line2 != line3) && (line1 != line3))
success = true;
return success;
}//두 변의 길이가 모두 다르다


public boolean is_isosceles(int line1,int line2,int line3){
boolean success = false;
if ((line1 == line2) || (line2 == line3) || (line1 == line3))
success =true;
return success;
}//정확히 두 변의 길이가 같다.


public boolean is_equilateral(int line1,int line2,int line3){
boolean success = false;
if ((line1 == line2 ) && (line2 == line3) && (line1 == line3))
success = true;
return success;
}//세 변의 길이가 모두 같다.
}
}




보여주신 소스를 위와 같이 수정하였습니다.


제가 컴파일하여 실행해보니 잘되는 군요.


단지 논리오류가 있어 직각삼각형을 식별못하지만....


수정된부분은 주석처리 다 해두었으니 참고하세요.


그리고 static문제는


함수를 static으로 선언하면 외부에서 그객체를 생성 않고도 함수를 class로만 call할 수있어 main과 같은 함수는 반드시 static으로 선언하는데 static과 nonstatic은 메모리 영역을 달리 써기 때문에 상호 의사소통에 제한이 있는 걸로 알고 있습니다.


도움이 되셨기를 바라며...


졸은 하루되세요~~






다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]