int x = 5;
x = x + 2;
System.out.println(x);
7
for (int i = 0; i < 3; i++) {
System.out.println(i);
}
0
1
2
int x = 7;
if (x > 5) {
System.out.println("A");
} else {
System.out.println("B");
}
A
if (x = 5) {
System.out.println("Hi");
}
= is used instead of ==.
What is a variable?
A place to store a value.
int a = 10;
int b = a - 3;
a = b + 1;
System.out.println(a);
8
int total = 0;
int[] nums = {2, 4, 6};
for (int n : nums) {
total = total + n;
}
System.out.println(total);
12
int x = 4;
if (x % 2 == 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
Even
for (int i = 0; i < 5; i++)
System.out.println(i);
There are no curly braces.
What does a loop do?
Repeats code multiple times.
int x = 4;
int y = x * 2;
x = y - x;
System.out.println(x);
4
int x = 10;
int count = 0;
while (x > 2) {
x = x - 2;
count = count + 1;
}
System.out.println(count);
4
int score = 85;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("C");
}
B
public static int add(int a, int b) {
System.out.println(a + b);
}
The method does not return anything.
What is the difference between return and System.out.println?
return sends a value back, println only prints.