In Java, there are 2 ways to perform input and output, namely through the command line and through GUI.
Command Line
- To perform an output to the command prompt window, you would use System.out.print() or System.out.println().
- To get an input from the user, you would use a Scanner class, as in the example program in Lab 1 Practice 4.
- You use entry.nextInt() to get an integer value, entry.nextDouble() to get a double value, and entry.nextLine() to get a string.
- To perform an output to a GUI window, you would use the showMessageDialog() method in the JOptionPane class.
- To get an input from the user, you would use the showInputDialog() method, as in the example program in Lab 1 Practice 5.
- Do take note that getting input from the user in a GUI is a 2-step process. The input value is always captured as a String object and you need to convert it into the appropriate data types in the 2nd step.
No comments:
Post a Comment