Java: getting inputs from Scanner and JOptionPane
A quick Java referece of getting inputs by using Scanner and JOptionPane.
import java.util.Scanner; import javax.swing.JOptionPane; public class GetInputs { public static void getInputsFromScanner() { String name; Scanner input = new Scanner(System.in); System.out.print("Enter your name > "); name = input.nextLine(); System.out.print("You entered your name as: "); System.out.println(name); } public static void getInputsFromJOptionPane() { String name; name = JOptionPane.showInputDialog(null, "Please enter your name"); JOptionPane.showMessageDialog(null,"Hi "+ name); } public static void main(String args[]) { getInputsFromScanner(); getInputsFromJOptionPane(); } }
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts