速求JAVA作业答案!!!~

来源:百度知道 编辑:UC知道 时间:2024/05/09 19:19:17
1.编写计算整数之和的方法。这些方法包括分别接受2,3,4,或5个整数作为参数的版本。
2.写出下面程序的运行结果
public class DeskCheck{
private static String a(int a, int b, int c){
return a+b+c+" ";
}
private static int b(int c){
System.out.print(c);
return c/2;
}
private static double b(double d){
int c = b( (int)d );
return c/2;
}
private static int c(int a, int c){
System.out.println("c");
return a/c;
}
public static void main(String[] args){
int a, b;
double c, d;
String s = "0";
a = 20;
b = 10;
c = 5;
d = 2.5;
a = b( a );
b = c( a, b );
c = c( b( b ), b );
d = b(c);
System.out.println(a(a,b,a));
System.out.println(c+d);
}
}
3.将下题的抽象类改写为接口,并实现其功能。
abstract class Shape{
abstract protected double area();
abstract protected void girth();
}
class Rectangle extends Shape{
float width,length;

1.public long sum(int [] a){
long sum = 0;
if(a!=null&&a.length>0){
for(int i=0;i<a.length;i++){
sum+=a[i];
}
}
return sum;
}
2.
20c
1c
021
0.0
3.
public interface Shape {
double area();
void girth();
}
public class Circle implements Shape {
float R;

Circle(float r) {
R = r;
}

public double area() {
return R * R * 3.14;
}

public void girth() {
System.out.println("The girth of circle : " + 3.14 * R * 2);
}
}