Posted at

【Java入門】時間がない人の為のメソッド例題

More than 5 years have passed since last update.


import java.util.*;

public class CMuse {

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

System.out.println("三角形の面積を計算します");
System.out.print("高さ:");
int a = scan.nextInt();
System.out.print("底辺:");
int b = scan.nextInt();

int result = Triangle(a,b);
int area = result / 2;

System.out.println("面積は"+area);

}

private static int Triangle(int a, int b) {
// TODO Auto-generated method stub

return a*b;

}

}

時間がない人の為のJava入門 

メソッド編