Since = in the program is an assignment, it can be self-assigned. I remember (substituting the right side for the left side)!
int x = 5;
x = x + 1;
//x becomes 6
++ is called the increment operator. This is an instruction to add 1 to the value of a variable and assign it. x++;
x = + 1;
//Both are the same, 1 is added to x
--Is called decrement and subtracts one.
There is a type called boolean. boolean can be true or false 。 Also called the truth value.
Remember that if it's true, it's true. If it's a lie, it's false. Alternatively, true if the switch is on, false if off
boolean a = true;
The comparison operator compares the left and right sides and returns a boolean.
== //equal(Mathematical=This is close to)
!= //Not equal
> //Left is larger than right
< //Left is less than right
>= //Left is above right
<= //Left is below right
It branches depending on whether the passed expression is true or false. if (conditional expression) {Process to be executed when the condition is true}
If you use else, the process that is executed when false is applied. if (conditional expression) {when the condition is true} else {when the condition is false}
You can use elseif to add another condition when false. if (condition 1) {when condition 1 is true} else if (condition 2) {when condition 1 is false and condition 2 is true} else {when both condition 1 and 2 are false}
Multiple conditions can be combined by using logical operators
! (NOT) Negation Example: When a is true,! A is false
&& (AND) The left and right sides are true (if both are the same) Example (a == 5 && b == 3) true when a is 5 and b is 3.
|| (OR)The left or right side is true(If either is ture, ok) Example(a<5 || b>=3)True when a is less than 5 or b is 3 or more
If there are no parentheses, calculate in the order of NOT AND OR
You can repeat it using the for statement.
for(int i = 0; i < 5; i++) {
System.out.println(i);
}
System.out.println(0);
System.out.println(1);
System.out.println(2);
System.out.println(3);
System.out.println(4);
Both are the same. for (variable used for Kaoru; condition to repeat; what to do once finished) The inside of the wave bracket is repeated. Counter variables can be used inside.
You can also put a for statement inside a for statement.
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; i++) {
//Inside is repeated 5 times
}
//When you come here, the outside is over once
}
Be careful not to make the counters the same! (In this example, it will be i and j.)
1,2,3,4,5,6,7,8,9, 2,4,6,8,10,12,14,16 ,,,Continue
Let's write a program that shows the multiplication table!
public class hello {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
String a = "";
for (int j = 1; j < 10; j++) {
a += i * j + ",";
}
System.out.println(a);
}
}
}
1,2,3,4,5,6,7,8,9,
2,4,6,8,10,12,14,16,18,
3,6,9,12,15,18,21,24,27,
4,8,12,16,20,24,28,32,36,
5,10,15,20,25,30,35,40,45,
6,12,18,24,30,36,42,48,54,
7,14,21,28,35,42,49,56,63,
8,16,24,32,40,48,56,64,72,
9,18,27,36,45,54,63,72,81,
It feels like ^^
I think there are other ways, so use the one that suits you ♪
while (condition) {}
while (x < y) {
//Repeated as long as x is less than y
}
If the condition is false from the beginning, it will never be executed
do {} while (condition) Even if the condition is false, it will be executed once for the time being
Goo is 1 Choki is 2 Par is 3 Enter the number of the first hand on the keyboard Enter the number of the second hand on the keyboard Show on the screen which one won and Aiko
Let's write a program!
Recommended Posts