I/O con JOptionPane

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

  1. import javax.swing.JOptionPane;
  2. JOptionPane.showInputDialog("...")
  3. JOptionPane.showMessageDialog(null, "...");
  4. Byte.parseByte(...)  // interi
    Short.parseShort(...)
    Integer.parseInt(...)
    Long.parseLong(...)
    Float.parseFloat(...) // decimali
    Double.parseDouble(...)
  5. (new Boolean(...)).booleanValue() // logici