gpt4 book ai didi

java - 问题 : Reading 10 different marks into my marks variable. FOR 循环

转载 作者:行者123 更新时间:2023-12-02 12:01:19 26 4
gpt4 key购买 nike

import java.util.*;

public class loops

{

public static void main (String []args)

{

Scanner input = new Scanner (System.in).useDelimiter("\n");

for (int i = 0; i <= 9; i++)
{
System.out.print("Enter your mark: ");
int marks = input.nextInt();
}

int marks = + input.nextInt();
int totalmarks = marks / 10;

System.out.println("The class average was:"+ totalmarks + ".");
}
}

最佳答案

问题没有明确提出,但根据我的解释,问题是将所有输入分数相加并给出平均值,因此声明一个初始值为 0 的 sum 变量并将所有作为输入的分数相加并取平均值.

import java.util.*;

public class loops

{

public static void main (String []args)

{

Scanner input = new Scanner (System.in).useDelimiter("\n");
int sum=0;
for (int i = 0; i <= 9; i++)
{
System.out.print("Enter your mark: ");
int marks = input.nextInt();
sum=sum+marks;
}


int totalmarks = sum / 10;

System.out.println("The class average was:"+ totalmarks + ".");
}
}

关于java - 问题 : Reading 10 different marks into my marks variable. FOR 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47239486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com