gpt4 book ai didi

java - 我无法弄清楚这 3 个相关错误

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

我有 3 个错误,我无法用我理所当然的低水平技能修复这些错误。

我只是想输入第一年的销售数据,这没问题,但我想把总销售额计算在输出值以下并收到错误。

C:\Users\Steven\Documents\assignment2.java:21: error: '.class' expected
System.out.println(int counter + "\t\t\t\t" + sales[counter]);

C:\Users\Steven\Documents\assignment2.java:21: error: not a statement
System.out.println(int counter + "\t\t\t\t" + sales[counter]);

C:\Users\Steven\Documents\assignment2.java:21: error: ';' expected
System.out.println(int counter + "\t\t\t\t" + sales[counter]);

代码:

import java.util.Scanner;

public class assignment2
{

public static void main(String [] args)
{

Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome\n");

System.out.println("Sales Month\t\tSales made");
int sales[]={60,54,62,67,54,67,51,50,62,55,49,70};
int sum=0;

for(int counter=0;counter < sales.length;counter++)
{
sum+=sales [counter];

}
System.out.println("The sum of the sales is " +sum);
System.out.println(int counter + "\t\t\t\t" + sales[counter]);

}

最佳答案

我想你需要这样的东西:

import java.util.Scanner;
public class assignment2 {

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome\n");
System.out.println("Sales Month\t\tSales made");
int sales[] = { 60, 54, 62, 67, 54, 67, 51, 50, 62, 55, 49, 70 };
int sum = 0;
for (int counter = 0; counter < sales.length; counter++) {
sum += sales[counter];
System.out.println(counter + "\t\t\t\t" + sales[counter]);
}
System.out.println("The sum of the sales is " + sum);
}
}

关于java - 我无法弄清楚这 3 个相关错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31004606/

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