import java.util.Scanner;
class Circle{
private double x,y;
private int radius;
public Circle (double x, double y, int radius) {
this.x = x;this.y = y;this.radius = radius;
}
public void show() {
System.out.println("가장 면적이 큰 원은 ("+x+","+y+")"+radius);
}
//원의 넓이 리턴
public double circle() {
return radius*radius*3.14;
}
}
public class CircleManager {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = new Scanner(System.in);
Circle c[] = new Circle[3];
for(int i=0;i<c.length;i++) {
System.out.print("x,y,radius >>");
double x = scanner.nextDouble();
double y = scanner.nextDouble();
int radius = scanner.nextInt();
c[i] = new Circle(x,y,radius);
}
double max=0; //제일 큰 원의 넓이 저장
int maxNum = 0; //제일 큰 원의 넓이의 i값을 저장
for(int i=0;i<c.length;i++) {
if(c[i].circle()>max) {
maxNum=i;
max = c[i].circle();
}
}
c[maxNum].show();
scanner.close();
}
}
결과
x,y,radius >>3.0 3.0 5
x,y,radius >>2.5 2.7 6
x,y,radius >>5.0 2.0 4
가장 면적이 큰 원은 (2.5,2.7)6
'명품JAVA프로그래밍 > 4장 클래스와 객체' 카테고리의 다른 글
[명품JAVA프로그래밍] 4장 실습문제 8번 (0) | 2021.12.27 |
---|---|
[명품JAVA프로그래밍] 4장 실습문제 7번 (0) | 2021.12.27 |
[명품JAVA프로그래밍] 4장 실습문제 5번 (0) | 2021.12.27 |
[명품JAVA프로그래밍] 4장 실습문제 4번 (0) | 2021.12.27 |
[명품JAVA프로그래밍] 4장 실습문제 3번 (0) | 2021.12.27 |