我正在制作一个程序来测试一些东西,但我无法弄明白。 我是一个初学者,这是伪java。所以不是真正的java。
只需考虑用户必须输入的输入,并打印为system.out.printl。
在一场正在进行的比赛中,有3个跑步俱乐部,每个俱乐部有10名跑步者。
跑步俱乐部A背面的数字是(从700到709)。
B俱乐部背面的数字是(从800到809)。
跑步俱乐部C背面的数字是(从900到909)。
在结束时,背面的数字被写下来。 比赛结束后,我们按顺序完成所有30个号码的列表。 我正在设计一个程序,告诉俱乐部赢得了这场比赛。 (名单前面数字最多的俱乐部)
到目前为止,我有这个。但我不确定这是正确的吗? 这种得分方式好吗?
annyone可以完成我吗?或者告诉我哪里错了?或者可以告诉我怎么做正确的方法? 非常感谢!
{
// declaration
// The points the clubs have
int pointsClubA,pointsClubB,pointsClubC;
// The runners that are finished
int finished;
// Position of the runner
int position;
// Het backnummer of the runner
int backnummer;
// Points beeing added to the clubs
int points
// De beginwaarden ingeven
finished = 0;
position = 1;
points = 31;
while (finished < 30)
{
print "What is the backnummer that just has finished";
input backnummer;
if (backnummer >= 700) && (backnummer < 710){
pointsClubA = pointsClubA + points;
}
else if ((backnummer >= 800) && (backnummer < 810)){
pointsClubB = pointsClubB + points;
}
else{
pointsClubC = pointsClubC + points;
}
print "On position nr",position,"its the runner with backnummer",backnummer,;
position = position + 1;
points = points -1;
finished = finished + 1;
} // End while module
// Now the points calculate with club has won
if (pointsClubA > pointsClubB) && (pointsClubA > pointsClubC){
print "Club A has won";
}
if (pointsClubB > pointsClubA) && (pointsClubB > pointsClubC){
print "Club B has won";
}
if ((pointsClubC > pointsClubA) && (pointsClubC > pointsClubB)){
print "Club C is de winnaar";
}
} // end program
非常感谢你帮助我! (我是初学者,所以给予一些信任:p)
答案 0 :(得分:0)
你的方法很好。您将能够实现目标。 以下方法也略有修改。
注意:我认为这不是真实案例。如果是这样,系统需要更有效地设计。您可能还想捕获其他详细信息,每次询问用户输入徽章编号都没有意义。而且,通过这种方法,我们无法捕获获胜者的顺序。它适用于简单的任务,但不适合现实世界的场景。
int numberOfPlayers = 30;
int pointsClubA = 0, pointsClubB=0, pointsClubC=0;
String winner = "";
for (int i=0; i< numberOfPlayers ; i++)
{
print "What is the number just finished?"
input backnumber;
if (backnumber >=700 && backnumber <= 709)
{
pointsClubA++;
}
else if (backnumber >=800 && backnumber <= 809)
{
pointsClubB++;
}
else if (backnumber >=900 && backnumber <= 909)
{
pointsClubC++;
}
else
{
print ("invalid");
}
print "On position nr",(i+1),"its the runner with backnummer",backnumber,;
} // End of for loop
int winningScore = Math.max (pointsClubA,pointsClubB, pointsClubC);
if (pointsClubA == winningScore)
{
winner = "Team A"
}
// Use if here instead of else if , because multiple winners are possible.
if (pointsClubB == winningScore)
{
if ("".equals(winner))
winner = " and Team B"
else
winner = "Team B"
}
if (pointsClubC == winningScore)
{
if ("".equals(winner))
winner = " and Team C"
else
winner = "Team C"
}
// Multiple winners are possible
print "Match Won By : " +winner;
// Sample outputs are:
// Match won by Team A
// Match won by Team B and Team C