mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-10 08:44:28 +02:00
fixed some issues & added a new array init
This commit is contained in:
@@ -19,10 +19,10 @@ Java is a general-purpose, concurrent, class-based, object-oriented computer pro
|
|||||||
Multi-line comments look like this.
|
Multi-line comments look like this.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Import Packages
|
// Import ArrayList class inside of the java.util package
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
// Import all "sub-packages"
|
// Import all classes inside of java.lang package
|
||||||
import java.lang.Math.*;
|
import java.lang.*;
|
||||||
|
|
||||||
// Inside of the learnjava class, is your program's
|
// Inside of the learnjava class, is your program's
|
||||||
// starting point. The main method.
|
// starting point. The main method.
|
||||||
@@ -93,6 +93,9 @@ int [] intArray = new int[10];
|
|||||||
String [] stringArray = new String[1];
|
String [] stringArray = new String[1];
|
||||||
boolean [] booleanArray = new boolean[100];
|
boolean [] booleanArray = new boolean[100];
|
||||||
|
|
||||||
|
// Another way to declare & initialize an array
|
||||||
|
int [] y = {9000, 1000, 1337};
|
||||||
|
|
||||||
// Indexing an array - Accessing an element
|
// Indexing an array - Accessing an element
|
||||||
System.out.println("intArray @ 0: "+intArray[0]);
|
System.out.println("intArray @ 0: "+intArray[0]);
|
||||||
|
|
||||||
@@ -118,9 +121,9 @@ int i1 = 1, i2 = 2; // Shorthand for multiple declarations
|
|||||||
|
|
||||||
// Arithmetic is straightforward
|
// Arithmetic is straightforward
|
||||||
System.out.println("1+2 = "+(i1 + i2)); // => 3
|
System.out.println("1+2 = "+(i1 + i2)); // => 3
|
||||||
System.out.println("1+2 = "+(i2 - i1)); // => 1
|
System.out.println("1-2 = "+(i2 - i1)); // => 1
|
||||||
System.out.println("1+2 = "+(i2 * i1)); // => 2
|
System.out.println("1*2 = "+(i2 * i1)); // => 2
|
||||||
System.out.println("1+2 = "+(i1 / i2)); // => 0 (0.5, but truncated towards 0)
|
System.out.println("1/2 = "+(i1 / i2)); // => 0 (0.5, but truncated towards 0)
|
||||||
|
|
||||||
// Modulo
|
// Modulo
|
||||||
System.out.println("11%3 = "+(11 % 3)); // => 2
|
System.out.println("11%3 = "+(11 % 3)); // => 2
|
||||||
|
Reference in New Issue
Block a user