函数题:sdut-oop-1-利用类实现求和(类和对象)
设计类Test,实现若干个数的累加功能。
请补充以下代码,完成输出要求。
### 函数接口定义:
class Test{
}
### 裁判测试程序样例:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, c, d, e;
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
d = in.nextInt();
e = in.nextInt();
Test rr = new Test();
int dd = rr.sum(a, b, c, d, e);
System.out.println(dd);
}
}
/* 请在这里填写答案 */
### 输入样例:
in
1 2 3 4 5
### 输出样例:
out
15
答案:若无答案欢迎评论
class Test {
public double sum(int a,int b,int c,int d,int e)
{
return (a+b+c+d+e)/5.0;
}
}
请补充以下代码,完成输出要求。
### 函数接口定义:
class Test{
}
### 裁判测试程序样例:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a, b, c, d, e;
a = in.nextInt();
b = in.nextInt();
c = in.nextInt();
d = in.nextInt();
e = in.nextInt();
Test rr = new Test();
int dd = rr.sum(a, b, c, d, e);
System.out.println(dd);
}
}
/* 请在这里填写答案 */
### 输入样例:
in
1 2 3 4 5
### 输出样例:
out
15
答案:若无答案欢迎评论
class Test {
public double sum(int a,int b,int c,int d,int e)
{
return (a+b+c+d+e)/5.0;
}
}