當前位置:編程學習大全網 - 編程軟體 - 編程題:在Java中

編程題:在Java中

import java.util.Scanner;

public class Circle {

private String color;

private int radius;

public Circle() {

}

// 顯示顏色

public String showColor() {

return color;

}

// 設置顏色

public void setColor(String color) {

this.color = color;

}

// 顯示半徑

public int showRadius() {

return radius;

}

// 設置半徑

public void setRadius(int radius) {

this.radius = radius;

}

// 計算周長

public double getGirth() {

return 2 * Math.PI * this.showRadius();

}

// 計算面積

public double getArea() {

return Math.PI * this.getGirth() * this.showRadius();

}

public static void main(String[] args) {

Circle circle = new Circle();

Scanner sc = new Scanner(System.in);

int count = 1;

int rad = 0;

String cor = null;

while(true){

if(count%2==1){

System.out.println("請輸入半徑:");

rad = sc.nextInt();

}else{

System.out.println("請輸入顏色:");

cor = sc.next();

circle.setRadius(rad);//設置半徑

circle.setColor(cor);//設置顏色

System.out.println("圓的半徑為:" + circle.showRadius() + " 顏色是:"

+ circle.showColor() + " 周長為:" + circle.getGirth() + " 面積為:"

+ circle.getArea());

}

count++;

}

}

}

  • 上一篇:手機怎麽樣才能投屏到電腦上?
  • 下一篇:制作PPT步驟
  • copyright 2024編程學習大全網