import java.io.*;
import java.util.*;
// declaration of the class
public class Bowling
{
// declaration of main program
public static void main(String[] args) throws FileNotFoundException
{
// 1. connect to input file
Scanner fin = new Scanner(new FileReader("bowling.txt"));
// declare arrays below
String Team, Member;
int teamw, teamb, Score;
// 2) initialize array accumulators to zero
teamw=0;
teamb=0;
int [] white_score = new int[3];
String [] white_member = new String[3];
int [] blue_score = new int[3];
String [] blue_member = new String[3];
// 3) display a descriptive message
System.out.println(
"This program reads the lines from the file bowling.txt to determine\n"
+ "the winner of a bowling match. The winning team, members and scores\n"
+ "are displayed on the monitor.\n");
// 4) test Scanner.eof() condition
while (fin.hasNext())
{
// 5) attempt to input next line from file
Member = fin.next();
Team = fin.next();
Score = fin.nextInt();
// 6) test team color is blue
// 7) then store blue member and score
// 8) increase blue array accumulator
// 9) else store white member and score
// 10) increase white array accumulator
if (Team.equals("Blue"))
{
blue_member[teamb]=Member;
blue_score[teamb] = Score;
teamb++;
}
else
{
white_member[teamw]= Member;
white_score[teamw]= Score;
teamw++;
}
}
// 11) if blue team score is larger
// 12) then display blue team as winner
// 13) else display white team as winner
if(sumArray(blue_score)>sumArray(white_score))
{
printArray("Blue", blue_member, blue_score);
}
else
{
printArray("White", white_member, white_score);
}
// 14 disconnect from the input file
fin.close();
}
public static int sumArray(int[] Score)
{
int sum=0;
for ( int i=0; i<Score.length; i++)
sum = sum+Score; ////HERE IS problem!!!!!!
return sum;
}
public static void printArray(String Team, String[] Member, int[] Score)
{
for(int i=0; i<Member.length; i++)
System.out.printf("winning team:"+Team+"\n"+Member+":"+Score);
}
}
错误显示这一行 我已经修复了代码: 是括号的一个问题,以后可以更新。
二进制运算符“*”的操作数类型不正确 我在编译过程中得到的错误是二进制运算符的操作数类型错误,它说:第一个类型:int,第二个类型:int[],我只能使用这个逻辑。以下是我的程序的一部分
我一直收到一个错误,说我不能使用布尔值,需要一个整数,但是N是一个整数,我只是想不出一个解决方案。
我不知道怎么了,我是个初学者。任何帮助都将不胜感激。
我不知道如何修正我错误。错误状态 “DayCare.java:29:错误:二进制运算符”-“[numDaysString-1])的操作数类型不正确)第一类型:String第二类型:int”
二进制运算符“!=”的操作数类型不正确第一种类型:String第二种类型:int 问题是根据NetBeans的