java函数 基础
package dubeg02; //梯形面积
public class Tast {
public static int add(int a, int b, int c) {
int D = (a + b) * c / 2;
toString(a, b, c);
return D;
}
public static void toString(int a, int b, int c) {
System.out.println("长" + a);
System.out.println("宽" + b);
System.out.println("高" + c);
}
public static void main(String[] args) {
int a = 22;
int b = 15;
int c = 17;
int sum = add(a, b, c);
System.out.println("梯形面积" + sum);
}
}
package dubeg02; 长方形面积//
public class Tast01 {
public static int add(int a, int b) {
int C = a*b;
toString(a, b);
return C;
}
public static void toString(int a, int b) {
System.out.println("长" + a);
System.out.println("宽" + b);
}
public static void main(String[] args) {
int a = 13;
int b = 999;
int sum = add(a, b);
System.out.println("长方形面积" + sum);
}
}
package dubeg02;三角形面积//
public class Tast03 {
public static int add(int a, int b) {
int C = a*b/2;
toString(a, b);
return C;
}
public static void toString(int a, int b) {
System.out.println("长" + a);
System.out.println("宽" + b);
}
public static void main(String[] args) {
int a = 1234;
int b = 5678;
int sum = add(a, b);
System.out.println("三角形面积" + sum);
}
}
package dubeg02; 圆面积//
public class Tast04圆 {
public static int add(int r ){
int b=(int)(Math.PI*r*r);
toString(r);
return b;
}
public static void toString(int r){
System.out.println("半径"+r);
}
public static void main(String[] args){
int r= 123;
int sum= add(r);
System.out.println("圆面积"+sum);
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。