Professional Documents
Culture Documents
import java.util.Scanner;
main class
System.out.println(name+": "+age);
# If statement
if(age > 0) {
System.out.println("Welcome!");
} else {
System.out.println("Too Young");
} else {
System.out.println("Error");
if(age <= 0) {
System.out.println("Error");
} else if(age <= 16) {
System.out.println("Too Young");
System.out.println("Welcome!");
} else {
System.out.println("Really?");
# Multiple conditions
System.out.println("Welcome!");
System.out.println("Welcome!");
## Do while
int x = 1;
do {
System.out.println(x);
x++;
## for loop
System.out.println(x);
## Arrays
int [] ages;
System.out.println(names[2]);
## for-each Loop
System.out.println(x);
## Multidimensional Arrays
## Matrix
int[][] sample = {
{1, 2, 3},
{4, 5, 6}
};
System.out.println(sample[x][y]);
}
## Methods
- Methods are reusable, we define them once and can call them multiple times.
- The void keyword means that the method does not return a value.