English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

if this is not how do i acheive this?
I am trying to read the array value of modelName[i] store it in inputName and the determine if inputName is == to the variable i am looking for (the models name) and then if it is display the whole line of code.

while ( response != null && response.length() > 0){
System.out.println("You are searching for " + response);
for (int i = 0; i < modelName.length; i++)
{
modelName[i] == inputName;
if (inputName == response)
System.out.println( modelName[i] + "\t\t" + digitStockNumber[i] + "\t" + modelColor[i] + "\t" + integerPrice[i] );
}
}

2007-07-15 16:28:52 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

ok but now my thing is in an infinite loop?

2007-07-15 18:12:20 · update #1

3 answers

(1) "==" is for comparison, not assignment. The line "modelName[i] == inputName" doesn't do anything (other than evaluate to true or false). It should instead be something like:

String inputName = modelName[i];

(2) "==" tests for object identity, and is not what you want to use for Strings in most cases.

"foo" == "foo" is not necessarily true, since there can be multiple (different) String objects whose contents is the same ("foo").

You want to use something like:

response.equals( inputName)
or
response.equalsIgnoreCase( inputName)

... depending whether you want a case-sensitive or case-insensitive compare. Also, since you've already checked response for null, it's better to use that as the object on which equals() is called -- otherwise unless you are very certain that each modelName[i] is non-null, you'd have to check inputName for null, before you could write it in the other order ("inputName.equals( response)")

---------
You have an infinite loop because you are not changing response within the while loop. Replace "while" with "if" -- or if you want to accept multiple responses from the user, then do that within the while loop (at the bottom, reassign response to the next line of input, or whatever).

2007-07-15 17:19:59 · answer #1 · answered by McFate 7 · 0 0

You need to change the first "while" loop to an "if" to avoid the endless loop problem. To assign a value to the variable inputName use
inputName = modelName[i].
To compare inputName with the response use the String objects equals method e.g. inputName.equals(response)

2007-07-15 19:58:21 · answer #2 · answered by zombo 1 · 0 1

i might get photos of Deaner donning his blue tights and deliver them to his pals and kin.. then placed them on youtube.. then publish a billboard close to the place he works.. then i might fairydust Nubs.. get lulu all of the blue eyeshadow she ever desires get Sil all of the steak he will ever want.. and wrap my little ones in bubblewrap and ultimately heal Jackpots shanking wound he have been given in penal complex!!

2016-10-03 21:50:13 · answer #3 · answered by ? 4 · 0 0

fedest.com, questions and answers