Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 21, 2017 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peter279k/6540eb698f16352f441a57e501e22e78 to your computer and use it in GitHub Desktop.
Save peter279k/6540eb698f16352f441a57e501e22e78 to your computer and use it in GitHub Desktop.
TQC+ JAVA
import java.util.Scanner;
public class JPA01 {
public static void main(String args[]) {
double totalarea;
System.out.printf("圓形面積為:%f \n", calCircle(5));
System.out.printf("三角形面積為:%f \n", calTriangle(10, 5));
System.out.printf("方形面積為:%f \n", calRectangle(5, 10));
totalarea = calCircle(5) + calTriangle(10, 5) + calRectangle(5, 10);
System.out.printf("此圖形面積為:%f \n",totalarea);
}
public static double calCircle(int num) {
return num * num * 3.1415926;
}
public static double calTriangle(int base, int height) {
return base * height / 2.0;
}
public static double calRectangle(int width, int height) {
return width * height;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment