Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Array Problems  RSS feed

 
Stephen Murphy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a problem getting an arry to display properly. I am reading in arguments from the command line. I would appreciate any help on this. My code is posted followed by my output, then my input.
My code looks something like this:
public class Tournament
{
public static void main(String[] args)
{
int sub = 1, count = 0, wins;
int arrayLength = args.length;
String team, rawWins;
Bracketer listGames= new Bracketer();
while (sub < args.length)
{
team = args[sub-1];
rawWins = args[sub];
wins = Integer.parseInt(rawWins);
listGames.listMaker(team, wins, count, arrayLength);
count = count + 1;
sub = sub + 2;
}
}
}

public class Bracketer
{
public Bracketer()
{
}
public void listMaker(String team, int wins, int count, int arrayLength)
{
int[] winList = new int[arrayLength];
String[] teamList = new String[arrayLength];
winList[count] = wins;
teamList[count] = team;
printArrays(winList, teamList);
}
public void printArrays(int[] winList, String[] teamList)
{
for(int i = 0; i <= (winList.length - 1); i++)
{
System.out.println(winList[i]);
System.out.println(teamList[i]);
}
}
}
My output (abbreviated):
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
5
myschool
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
4
campbell
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
0
null
my command line input (or something like it):
UCLA 4 myschool 5 campbell 4 UNCC 12 ...(up to 64 sets of team \wins)
 
Stephen Murphy
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind guys!! I figured it out. but see if you can find the error. Thanks,
Pat
 
Bikramjit Singh Bajwa
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,
It was really small problem...
check this out..

public class Tournament
{
public static void main(String[] args)
{
int sub = 1, count = 0, wins;
int arrayLength = args.length;
String team, rawWins;
Bracketer listGames= new Bracketer();
while (sub < args.length)
{
team = args[sub-1];
rawWins = args[sub];
wins = Integer.parseInt(rawWins);
listGames.listMaker(team, wins, count, arrayLength);
count = count + 1;
sub = sub + 2;
}
}
}

class Bracketer
{
public Bracketer()
{
}
public void listMaker(String team, int wins, int count, int arrayLength)
{
int[] winList = new int[1];
String[] teamList = new String[1];
winList[0] = wins;
teamList[0] = team;
printArrays(winList, teamList);
}
public void printArrays(int[] winList, String[] teamList)
{
for(int i = 0; i <= (winList.length - 1); i++)
{
System.out.println(winList[i]);
System.out.println(teamList[i]);
}
}
}

Chakk de
Bikram
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!