JAVA method (230620)

이원건·2023년 6월 20일
0

JAVA

목록 보기
9/33
post-thumbnail

1. 아래 함수를 만드시오.

  • 문제
double area = getCircleArea(10);
System.out.println(area); //314.0

area = getRectangleArea(10,20);
System.out.println(area); //200.0
				
area = getTriangleArea(40,20);
System.out.println(area); //400.0
		
int code = getAscCode('A');
System.out.println(code); //65
  • 코드
public class MethodExamples {
	public static void main(String[] args) {
		double area = getCircleArea(10);
		System.out.println(area); // 314.0
		
		area = getRectangleArea(10, 20);
		System.out.println(area);	// 200.0;
		
		area = getTriangleArea(40, 20);
		System.out.println(area);  // 400.0;
		
		int code = getAsciiCode('A');
		System.out.println(code);	//65
		
	}
	
	static int getAsciiCode(char ch) {
		return (int)ch;
	}
	
	
	static double getTriangleArea(int w, int h) {
		return 0.5*w*h;
	}
	
	static double getRectangleArea(int x, int y) {
		return x*y;
	}
	
	static double getCircleArea(int r) {
		final double PI = 3.14;
		return r*r*PI;
	}
	
}
  • 결과
314.0
200.0
400.0
65

0개의 댓글