【发布时间】:2018-09-19 14:58:43
【问题描述】:
我是一名学习 Java 的 AP 计算机科学专业的学生。在参加本课程之前,我学习了 JavaScript,但我无法弄清楚如何完成这段代码。我的老师在休假,我们的孩子不是程序员。我很感激任何帮助。我的老师希望我们让 cmets 解释一切。 这是我的代码:
package com.company;
//导入扫描仪类和任何其他需要的可导入类
导入 java.util.*;
公共类主{
public static void main(String[] args) {
//Asks a question and lets the user input an answer, saved as the int Dividend
System.out.println("How many numbers do you want to average?");
Scanner dividend = new Scanner(System.in);
int Dividend = dividend.nextInt();
//this is a variable set in order to make the while statement work for any number
int change = 0;
//Asks for the numbers that should be averaged
System.out.println("Enter the numbers to find their average: ");
/*This is saying that while change is less than the amount of numbers being averaged,
continue to provide an input for numbers*/
while (change <= Dividend) {
int Num = 0;
int nums = 0;
Scanner num = new Scanner(System.in);
//I am trying to add the input to num so I can average them
nums = num.nextInt();
Num += nums;
/*this is making sure that change is letting the code run through the exact amount of necessary times
in order to input the correct amount of numbers*/
change++;
//once all of the numbers have been put in, average them
if (change == Dividend) {
System.out.println("Average: " + Num / Dividend);
}
System.out.println(Num);
}
}
}
【问题讨论】:
-
你能解释一下什么是变化吗?
-
还有什么股息是它没有宣布
-
对不起,我的一些代码没有复制,这里是完整的代码:
标签: java