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.