Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package labexercises\lab3; // folder which contains the Java files
- import java.util.Scanner; // required to use a Scanner to get info from keyboard
- /**
- * This is a javadocs comment. Always have one of these comments in
- * front of every class and method.
- * Type an * before every line for the comment to look nice!
- *
- * @author your name
- * @version date as yyyy-mm-dd
- */
- // class header: class name is the same as the filename
- public class Skeleton { // classes start & end with curly braces
- // main method: required in an application class
- public static void main(String [] args) {
- // methods start & end with curly braces
- // Code within the main method is indented for better readability.
- // You can also add blank lines wherever you want
- // Start by declaring any variables.
- // try to put all variables at the top of the method
- // Syntax is: dataType variableName;
- int number, doubleIt;
- //Create a scanner object if you are getting info from console keyboard.
- Scanner keyboard = new Scanner(System.in);
- // If you want input you must tell the user what you want
- System.out.print("Please enter a whole number: ");
- // Use the Scanner object to read the input and assign it to a variables.
- // Syntax: varName = keyboard.nextDouble(); (or nextInt(), or...)
- number = keyboard.nextInt();
- // Once you have all your input, do your calculations.
- // how assignment works: the expression on the right
- // hand side of the equal sign is evaluated and the result is stored
- // in the variable on the left hand side
- doubleIt = number * 2; // multiply input by 2
- //Display the results to the user. Syntax is
- // System.out.println("blah blah: "+ resultVariable);
- System.out.println("You typed in: " + number);
- System.out.println("Doubled it's: " + doubleIt);
- } // main method: close
- } // Skeleton class: close
Advertisement
Add Comment
Please, Sign In to add comment