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

Help needed with ARRAYS, please.  RSS feed

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays are still a sticking point for me that I cannot get my head around but still keep trying and I was hoping that those on this list who are more fluent in its uses could help me with the code below. As you can see in my method below I have two arrays that I have to account for, described by my two while statements. There must be a better way to handle this more efficiently that what I have attempted to do as well as return a BigInteger value. Any help or direction would be appreciated.

Here is the code:

public BigInteger getUserLimit(User user){
String userid = user.getUserID();
String[] userlimit = user.getNsklmt();
String entity = getRequisitionID().getEntity();
String[] hospcodes = user.getHospcodes();
int i = 0;
while (userlimit == null && i < hospcodes.length){
BigInteger nsklmt = new BigInteger("0");
i++;
return nsklmt;
}
while (userlimit != null && i < hospcodes.length){
String ul = userlimit.toString();
float amount = Float.valueOf(ul).floatValue();
float userl = amount * 100;
String userlmt = Float.toString(userl);
BigInteger nsklmt = new BigInteger(userlmt);
i++;
return nsklmt;
}
}

Thank you.
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1st up here's your code indented, use the code tag to preserve this.



From that code I have no idea what those loops are there for, you assign userlimit a value that may or may not be null, you loop checks the condition and regardless what happens inside the loop you return a value which means your method ends. Nothing more to offer. At most that loop will run once. The second loop you check that it's not null but still that loop will run once and finished.

Here's how I'd iterate over an array, there are other ways, and your while loop can be modified to work, but having too little information I'll recommend possible the most widely used solution.


 
Ray Horn
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your intent was to access the elements of your array in your 2nd while loop:


Then you need so use the [] to specify the array element you want; as in:
String ul = userlimit[i].toString();
[ November 03, 2005: Message edited by: Ray Horn ]
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray,

Thanks for the response. Your time and help are appreciated.

Regards.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!