• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Array Problems

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind guys!! I figured it out. but see if you can find the error. Thanks,
Pat
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic