Nothing missing, rewrite while loop as proposed...
--
Martin
Dne pátek, 28. února 2014 21:20:18 UTC+1 Jaya napsal(a):
>
> Martin,
>
> Actually, it is not working right for me. I am only getting else condition
> value all the time.
> See the attached for my test with correct values.
> Can you please let me know what is missing in my code?
> Thanks,
> Jaya
>
>
> On Friday, February 28, 2014 2:10:10 PM UTC-6, Jaya wrote:
>>
>> Thanks Martin.
>> It worked now.
>> Is everything else look OK then?
>>
>> Thanks,
>> Jaya
>>
>> On Friday, February 28, 2014 2:07:41 PM UTC-6, Martin wrote:
>>>
>>> You are using assignement operator in while "=" instead of comparator
>>> operator "=="
>>> --
>>> Martin
>>>
>>> Dne pátek, 28. února 2014 20:57:18 UTC+1 Jaya napsal(a):
>>>>
>>>> I am actually using Eclipse as it has already been installed to my
>>>> computer.
>>>> Here is the text from Console:
>>>> Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 8
>>>> at ForLoop2.main(ForLoop2.java:20)
>>>>
>>>> Screenshot attached too.
>>>>
>>>> Thanks,
>>>> Jaya
>>>>
>>>> On Friday, February 28, 2014 1:50:56 PM UTC-6, Martin wrote:
>>>>>
>>>>> Can you paste here screenshot from NetBeans including line numbers and
>>>>> error you are getting?
>>>>> --
>>>>> Martin
>>>>>
>>>>> Dne pátek, 28. února 2014 20:48:00 UTC+1 Jaya napsal(a):
>>>>>>
>>>>>> Home work is as follows:
>>>>>> The homework is to modify the MyForLoopProject project (Exercise 2
>>>>>> above) described below. (You might want to create a new project by
>>>>>> copying the MyForLoopProject project.) You can name the new project
>>>>>> in any way you want but here I am going to call to call it as
>>>>>> MyOwnWhileProject.
>>>>>>
>>>>>> Instead of using for loop, use while loop.
>>>>>>
>>>>>> My Question:
>>>>>> Do I need to create a 'try catch' block to create a while loop ?
>>>>>>
>>>>>> My code is as follows, but I am getting exception error when I have
>>>>>> an invalid value. Please review and let me know what I need to do here.
>>>>>>
>>>>>> import javax.swing.JOptionPane;
>>>>>>
>>>>>> public class ForLoop2 {
>>>>>> public static void main(String[] args) {
>>>>>> String names
>>>>>> []={"Beah","Bianca","Lance","Belle","Nico","Yza","Gem","Ethan"};
>>>>>> String searchName = JOptionPane.showInputDialog("Enter
>>>>>> either \"Yza\" or \"noname\"!");
>>>>>> // Declare and initialize boolean primitive type variable
>>>>>> called foundName.
>>>>>> boolean foundName =false;
>>>>>> int i = 0;
>>>>>>
>>>>>> while(foundName=true){
>>>>>> if (names [i ].equals(searchName)){
>>>>>> foundName =true;
>>>>>> break;
>>>>>> }
>>>>>> // System.out.println(searchName + "found" + i + "times");
>>>>>>
>>>>>> i++;
>>>>>> }
>>>>>>
>>>>>> // Display the result
>>>>>> if (foundName)
>>>>>> JOptionPane.showMessageDialog(null, searchName + " is
>>>>>> found!");
>>>>>> else
>>>>>> JOptionPane.showMessageDialog(null, searchName + " is not
>>>>>> found!");
>>>>>> }
>>>>>> }
>>>>>>
>>>>>>
--
You received this message because you are subscribed to the Google Groups
"JPassion.com: Java Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/jpassion_java.
For more options, visit https://groups.google.com/groups/opt_out.