campbe13

Skeleton.java

Jan 31st, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package labexercises\lab3;  // folder which contains the Java files
  2. import java.util.Scanner; // required to use a Scanner to get info from keyboard
  3.  
  4. /**
  5.  *  This is a javadocs comment. Always have one of these comments in
  6.  *  front of every class and method.
  7.  *  Type an * before every line for the comment to look nice!
  8.  *
  9.  *   @author your name
  10.  *   @version date as yyyy-mm-dd
  11.  */
  12. // class header:  class name is the same as the filename
  13. public class Skeleton  {       // classes start & end with curly braces
  14. // main method: required in an application class
  15.     public static void main(String [] args)     {
  16.         // methods start & end with curly braces
  17.  
  18.         // Code within the main method is indented for better readability.
  19.         // You can also add blank lines wherever you want
  20.  
  21.         // Start by declaring any variables.
  22.         // try to put all variables at the top of the method
  23.         // Syntax is: dataType variableName;
  24.         int number, doubleIt;
  25.  
  26.         //Create a scanner object if you are getting info from console keyboard.
  27.         Scanner keyboard = new Scanner(System.in);
  28.  
  29.         // If you want input you must tell the user what you want
  30.         System.out.print("Please enter a whole number: ");
  31.         // Use the Scanner object to read the input and assign it to a variables.
  32.         // Syntax: varName = keyboard.nextDouble(); (or nextInt(), or...)
  33.         number = keyboard.nextInt();
  34.  
  35.         // Once you have all your input, do your calculations.
  36.         // how assignment works: the expression on the right
  37.         // hand side of the equal sign is evaluated and the result is stored
  38.         // in the variable on the left hand side
  39.         doubleIt = number * 2;   // multiply input by 2
  40.  
  41.         //Display the results to the user. Syntax is
  42.         // System.out.println("blah blah: "+ resultVariable);
  43.         System.out.println("You typed in: " + number);
  44.         System.out.println("Doubled it's: " + doubleIt);
  45.  
  46.     }  // main method: close
  47. } // Skeleton class: close
Advertisement
Add Comment
Please, Sign In to add comment