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 :(得分:1)
问题没有明确要求,但根据我的解释,问题是添加所有输入标记并给出平均值,因此声明一个初始值为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 + ".");
}
}