小编jja*_*n89的帖子

用于循环结构

该程序将使用for循环计算4个考试的平均成绩,方法是一次一个地提示用户输入考试成绩,然后计算平均值并显示结果.

public class ExamsFor4 {

public static void main(String[] arguments) {


int inputNumber; // One of the exams input by the user.
int sum = 0;     // The sum of the exams.
int i;       // Number of exams.
Double Avg;      // The average of the exams.

TextIO.put("Please enter the first exam: ");        // get the first exam.
inputNumber = TextIO.getlnInt();    

for ( i = 1; i <= 4; i++ ) {  

    sum += inputNumber;                 // Add inputNumber to running sum. …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
1268
查看次数

如何使用'for循环'代替'while循环'

不得不使用while,do-while和for循环为在线java类编写以下程序.寻找一点解释.提前致谢!
PS虽然寻找参考书籍是Java还是Javascript?有关好的参考书的任何建议吗?我得到了这个概念,大多数情况下,魔鬼肯定在细节中.

public class ExamsFor {

    public static void main(String[] arguments) {


    int inputNumber; // One of the exams input by the user.
    int sum;     // The sum of the exams.
    int count;   // Number of exams.
    Double Avg;    // The average of the exams.


    /* Initialize the summation and counting variables. */

    sum = 0;
    count = 0;

    /* Read and process the user's input. */

    TextIO.put("Please enter the first exam: "); // get the first exam.


        inputNumber = …
Run Code Online (Sandbox Code Playgroud)

java

0
推荐指数
1
解决办法
310
查看次数

标签 统计

java ×2