devxlogo

Integer input

Integer input

Question:
What’s the best way to read in an integer fromthe keyboard for further use?

Answer:
You can probably find numerous examples of this by browsing through theJava section here at inquiry.com. From a GUI the easiest method is to use a textfield:

   Class Demo extends Frame {      private TextField numField;      private int num;      public boolean action(Event e, Object arg) {         if (e.target == numField)            num =                Integer.valueOf(numField.getText()).intValue();         // etc.      }      // etc.   }

devx-admin

Share the Post: