- JOptionPane.showInputDialog("...") - Shows a dialog requesting input from
the user. It always returns String with users input.
- Integer.parseInt( ... ) - It converts String with user input to an
Integer. It is done wrong, because there is no check if User actually
inputs a number. It needs a catch for an exception.

To get a String from a User:
String inputValue = JOptionPane.showInputDialog("Please input a value");

Javadoc:
http://docs.oracle.com/javase/7/docs/api/javax/swing/JOptionPane.html
Tutorial for a JOptionPane:
http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html




2014-03-24 2:57 GMT+01:00 Jaya <[email protected]>:

> As per the exercise, we have this following code. Can someone explain
> these highlighted lines of code and how do we do this for Strings?
>
> import javax.swing.JOptionPane;
>
> public class GreatestNumber {
>         public static void main(String[] args) {
>         int[] num = new int[10];
>         int counter;
>         int max = 0;
>         int totalnumber = 3;
>
>         // Prompt a user to enter numbers
>         for(counter = 0; counter < totalnumber; counter++){
>
>             num[counter] = Integer.parseInt
>                     (JOptionPane.showInputDialog("Enter numbers until " +
> totalnumber + " numbers are entered"));
>
>             // Compute the greatest number up to this point
>             if((counter == 0)||(num[counter] > max))
>                 max = num[counter];
>         }
>
>         // Display the greatest number.
>         JOptionPane.showMessageDialog(null,"The number with the greatest
> value is " + max);
>     }
>
> }
>
>
> Thanks,
> Jaya
>
> --
> 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/d/optout.
>

-- 
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/d/optout.

Reply via email to