diff options
Diffstat (limited to 'java.html.markdown')
| -rw-r--r-- | java.html.markdown | 49 | 
1 files changed, 42 insertions, 7 deletions
| diff --git a/java.html.markdown b/java.html.markdown index 772dc25d..3ec938ef 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -10,6 +10,7 @@ contributors:      - ["Rachel Stiyer", "https://github.com/rstiyer"]      - ["Michael Dähnert", "https://github.com/JaXt0r"]      - ["Rob Rose", "https://github.com/RobRoseKnows"] +    - ["Sean Nam", "https://github.com/seannam"]  filename: LearnJava.java  --- @@ -29,13 +30,13 @@ Multi-line comments look like this.   * attributes of a Class.   * Main attributes:   * - * @author 		Name (and contact information such as email) of author(s). - * @version 	Current version of the program. - * @since		When this part of the program was first added. - * @param 		For describing the different parameters for a method. - * @return		For describing what the method returns. + * @author         Name (and contact information such as email) of author(s). + * @version     Current version of the program. + * @since        When this part of the program was first added. + * @param         For describing the different parameters for a method. + * @return        For describing what the method returns.   * @deprecated  For showing the code is outdated or shouldn't be used. - * @see 		Links to another part of documentation. + * @see         Links to another part of documentation.  */  // Import ArrayList class inside of the java.util package @@ -51,6 +52,14 @@ public class LearnJava {      // point.      public static void main (String[] args) { +    /////////////////////////////////////// +    // Input/Output +    /////////////////////////////////////// + +        /* +        * Ouput +        */ +          // Use System.out.println() to print lines.          System.out.println("Hello World!");          System.out.println( @@ -65,6 +74,32 @@ public class LearnJava {          // Use System.out.printf() for easy formatted printing.          System.out.printf("pi = %.5f", Math.PI); // => pi = 3.14159 +        /* +         * Input +         */ + +        // use Scanner to read input +        // must import java.util.Scanner; +        Scanner scanner = new Scanner(System.in); + +        // read string input +        String name = scanner.next(); + +        // read byte input +        byte numByte = scanner.nextByte(); + +        // read int input +        int numInt = scanner.nextInt(); + +        // read long input +        float numFloat - scanner.nextFloat(); + +        // read double input +        double numDouble = scanner.nextDouble(); + +        // read boolean input +        boolean bool = scanner.nextBoolean(); +          ///////////////////////////////////////          // Variables          /////////////////////////////////////// @@ -717,7 +752,7 @@ class Dog extends Animal      public void makeSound()      {          System.out.println("Bark"); -        // age = 30;	==> ERROR!	age is private to Animal +        // age = 30;    ==> ERROR!    age is private to Animal      }      // NOTE: You will get an error if you used the | 
