직각 삼각형 판단까지...


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

글쓴이 :박찬우 2000년 5월 18일 10:36:13

In Reply to: good luck~~ posted by 이지연 on 2000년 5월 18일 09:36:36:


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.print ("line1 : ");
line1 = Integer.parseInt(stdin.readLine());


System.out.print ("line2 : ");
line2 = Integer.parseInt(stdin.readLine());


System.out.print ("line3 : ");
line3 = Integer.parseInt(stdin.readLine());



//삼각형의 타입을 결정한다.
if (tri1.is_right( line1, line2, line3))
System.out.println ("\n직각 삼각형입니다.");


if (tri1.is_scanlene( line1, line2, line3))
System.out.println ("\n두변의 길이가 모두 다르다.");


if (tri1.is_isosceles( line1, line2, line3))
System.out.println ("\n정확히 두 변의 길이가 같다.");


if (tri1.is_equilateral( line1, line2, line3))
System.out.println ("세 변의 길이가 모두 같다.");



System.out.println("\n끝내려면 엔터를 누르세요.");
stdin.readLine();
}//클래스 Triangle



//class Triangle_control {
static class Triangle_control {
int l1,l2,l3;


public boolean is_right(int line1,int line2,int line3){
return pandan(line1, line2, line3);
}//직각 삼각형



//직각삼각형인지 판단하는 루틴 #1 : 소트를 해서 가장 큰 변을 구하여 판단할 수도 있을 것이다.


//
public boolean pandan(int a, int b, int c) {
boolean val = false;


if (a*a == (b*b + c*c)) {
val = true;
}


if (b*b == (c*c + a*a)) {
val = true;
}


if (c*c == (a*a + b*b)) {
val = true;
}


return val;
}//판단 끝



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;
}//세 변의 길이가 모두 같다.
}



}



결과는 다음과 같습니다.

삼각형의 세 변을 입력하시오.
line1 : 5
line2 : 12
line3 : 13


직각 삼각형입니다.


두변의 길이가 모두 다르다.


끝내려면 엔터를 누르세요.





다음 글들:



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

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


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