Commit 31e68cf5 by michael lundquist

### Adding notes from ch1 and starting on code for ch1

parent d24fd138
 import java.util.Scanner; //import public class Main{ public static void main(String[] args){ java.util.zip.Deflater def; } /** * Checks if a nubmer is even. Exercise 1.4 * * @param i the input to test for evenness * @return true if it's even, else false. */ public static boolean isEven(int i){ if((i & 1) == 1)//deletes all the other digits, leaving only the 1s place return false; return true; } /** * R-1.5 * returns the sum of all positive integers up to and including n * @param n * @return */ public static int sumToN(int n){ return (n + 1 * (n/2)) + (isEven(n)? 0: ((int) n/2) + 1); } /** * R-1.6 * gives the sum of all the odd positive integers up to and including n * @param n * @return */ public static int sumOddsToN(int n){ int val = 0; if(!isEven(n)){ val = ((int) n/2) + 1; } int preSum = sumToN(n); return preSum/2 +n; } } \ No newline at end of file
 ... ... @@ -3,7 +3,7 @@ ## 1.1 Getting Started - The book describes writing hello world, java key words... - __method__: executible statements inside java functions - __method__: executable statements inside java functions - __class__ - __block__: code contained with braces ("{" and"}") ... ... @@ -42,7 +42,7 @@ - _double_: 64-bit floating-point number (IEEE 754-1985) - 8 bytes, 16 decimal digits `double e = 2.72342;` - In java, uninitalized base types variables are assigned a default value. By default: - In java, uninitialized base types variables are assigned a default value. By default: - numeric types are `0` - boolean types are `false` - character types are `null` ... ... @@ -100,7 +100,7 @@ - __Access control modifiers__: control the level of access (aka *visibility*) the defining class grants to other classes. - __public__: all classes may access this member using dot notation - in java, public (non inner) classes must be defined in their own file whose file name matches the class name. - in java, public (non inner) classes must be defined in their own file whose file name matches the class name. You may only have 1 public, non-inner class per file. - __Protected__: access is only granted to *subclasses* of the class and other classes in the same *package* - __subclasses__: classes that inherit from a class (see 2.2) - __package__ (see 1.8) ... ... @@ -122,7 +122,7 @@ ##### The __final__ Modifier - variables initialized with the final varaible can't be reassigned. - variables initialized with the final variable can't be reassigned. - final reference variables always refer to the same object - final variables are typically static ... ... @@ -149,7 +149,7 @@ - see earlier for public, private and static modifiers. - the *returnType* defines what type of value the function returns, or `void` for no return value. - each paramater has a *type* and a name (*paramName* in this example) - each parameter has a *type* and a name (*paramName* in this example) - the parameter list can be empty ##### Return types ... ... @@ -184,7 +184,7 @@ - Constructors can't be __static__, __abstract__, or __final__ only the access modifiers are allowed (private, public, protected) - constructors don't have a return type, and don't return anything. The __new__ operator that's called with the constructor gets a reference to the created object. - like methods, constructors can be overloaded with different signitures. - like methods, constructors can be overloaded with different signatures. - Java provides a default constructor with no parameters. If you create a custom overloaded constructor, the default constructor isn't provided. #### The Keyword __this__ ... ... @@ -197,7 +197,7 @@ #### The main Method - Java classes that have a __main__ method are executible from the command line. - Java classes that have a __main__ method are executable from the command line. - main method syntax: ... ... @@ -219,7 +219,7 @@ public static void main(String[] args){ ## 1.3 Strings, Wrappers, Arrays and Enum Types ### The String Class ### The String Class - Java's __char__ base type stores a single character from the 16-bit unicode international alphabet. - character literals are surrounded by single quotes, 's'. ... ... @@ -269,7 +269,7 @@ public static void main(String[] args){ ### Arrays - Arrays store homoginous data. Each cell (element) in an array is stored at an index. - Arrays store homogeneous data. Each cell (element) in an array is stored at an index. #### Array Elements and Capacities ... ... @@ -326,12 +326,12 @@ public static void main(String[] args){ #### Arithmetic Operators - The arithmetic operators are: - + addition - - subtraction - * multiplication - \+ addition - \- subtraction - \* multiplication - / division - % modulo - - uniary negation - \- unary negation - parentheses can be used to define the order of operations. - Java doesn't allow operator overloading for class types. ... ... @@ -538,7 +538,7 @@ public static double sum(double[] data){ ### Simple Output Methods - Java's print methods print to "standard output". Generally this goes to the shell, but can be redirected, for example, to a file. - Java's `System.out` is an instance of `java.io.PrinteStream` which stores output in a *buffer* before it prints it empties it to the console. - Java's `System.out` is an instance of `java.io.PrintStream` which stores output in a *buffer* before it prints it empties it to the console. - System.out print methods: - `print(String s)` Prints s ... ... @@ -593,4 +593,165 @@ public class InputExample{ ## 1.8 Packages and Imports - \ No newline at end of file - Java allows related type definitions to be grouped into a __package__. - remember, type definitions are: - __classes__, which have some [rules about access modifiers at the file level](#Access-Control-Modifiers) as you'll recall. These rules make packaging unambiguous. - __enums__, which have this [syntax](#Enum-Types) as you'll recall - For types to belong to a package named *packageName*, they must be located in a directory named *packageName* and each file must begin with the line:
package packageName;