Advertisement
campbe13

Lecture 3/4 sample 1 Skeleton.java

Aug 29th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. //package dawson112.labexercises; // the folders which contain .java file wrt H:
  2.  
  3. import javax.swing.JOptionPane; // required to use a JOptionPane for input from user
  4.  
  5. /**
  6.  *   Here you put a short explanation of the purpose of your code.
  7.  *   This is a javadocs comment. Always have one of these comments in front of every
  8.  *   class and method. Use extra * before every line and indent for the comment to look nice!
  9.  *
  10.  *   @author: your name
  11.  *   @version: date
  12.  */
  13.  
  14. // A class header. The class name is same as filename
  15. // A class is delimited by brace brackets
  16. public class Skeleton {
  17.  
  18.     // main method is required
  19.     // Methods are also delimited by brace brackets
  20.     public static void main(String[] args) {
  21.  
  22.             // Code within the main method is indented for readability.  
  23.             // You can also add blank lines for readability
  24.             // Usually start by declaring any variables. Syntax is: type variableName;
  25.  
  26.             int number;
  27.             String inputString; //used with JOptionPane for user input in text
  28.  
  29.             // Accepting number input with JOptionPane has two steps
  30.             // 1- get the input into a string
  31.             // 2- convert the string to the data type that you asked for
  32.  
  33.             inputString = JOptionPane.showInputDialog("Enter a whole number: ");
  34.             number = Integer.parseInt(inputString);
  35.  
  36.             // Once you have all your input, do your calculations.
  37.             // Display the results to the user.
  38.             // Syntax is System.out.println("blah blah: "+ resultVariable);
  39.  
  40.             System.out.println("You entered: " + number);
  41.  
  42.         } // Brace to close the main method.
  43.  
  44.     // Braces should be aligned with the matching opening brace for readability
  45.  
  46. } // Brace to close the class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement