public class lianxi03 {
public static void main (String[] args) {
int number = 20;
int xx = sum(number);
int average = xx / number;
System.out.println("1到" + number + "之间的数之和是" + xx + "它们的平均数是" + average);
}
public static int sum(int num) {
int x = 1;
int y = 0;
while (x <= num)
{
y = y + x;
x++;
return y;
}
}
}
|
|