0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JAVA引数と戻り値-三角形、円の面積を求める

Last updated at Posted at 2015-10-14

▪️問題1


メソッド名:calcTriangleArea
戻り値の型:三角形の面積(double)
引数リスト:三角形の底辺の長さ、単位はcm(double bottom)
                   三角形の高さ、単位はcm(double height)
処理内容:引数を使用して面積を求め、それを戻す



メソッド名:calcCircleArea
戻り値の型:円の面積(double)
引数リスト:円の半径、単位はcm(double radius)
                   三角形の高さ、単位はcm(double height)
処理内容:引数を使用して面積を求め、それを戻す


mainメソッドからそれぞれのメソッドに適当な引数を渡して呼び出し、戻り値を出力して正しい面積が表示されるかを確認して下さい。

▪️問題1ソースコード

public class test35 {
	public static void main(String[] args) {
		double triangleArea = calcTriangleArea(10.0, 5.0);
		System.out.println("三角形の面積:" + triangleArea + "平方cm");
	}

	public static double calcTriangleArea(double bottom, double height) {
		double area = (bottom * height) / 2;
		return area;
	}
}

▪️問題1 実行結果
三角形の面積:25.0平方cm

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?