Input/output con GUI
import javax.swing.JOptionPane; public class IO { public static void main(String[] args) { // input String stringa = JOptionPane.showInputDialog("Inserisci un intero"); int x = Integer.parseInt(stringa); // elaborazione // ... // output JOptionPane.showMessageDialog(null, "Hai inserito " + x); } }
Note
-
import javax.swing.JOptionPane;
-
JOptionPane.showInputDialog("...")
-
JOptionPane.showMessageDialog(null, "...");
-
Byte.parseByte(...) // interi Short.parseShort(...) Integer.parseInt(...) Long.parseLong(...) Float.parseFloat(...) // decimali Double.parseDouble(...)
-
(new Boolean(...)).booleanValue() // logici