java
System.out.println();
#The value taken as an argument is displayed on a new line.
System.out.print();
#Display the value taken as an argument without line breaks.
int variable name= Math.max( a , b );
#Compare the arguments and substitute the larger number.
int variable name= Integer.parseInt(String or String type variable);
#Convert a string to a number. For example"100"And,,,
int variable name= new java.util.Random().nextInt(upper limit);
#nextInt();If you take a number as an argument with, numbers less than that number are randomly generated.(0~Less than the upper limit)
String variable name= new java.util.Scanner(System.in).nextLine();
#Accepts the input of one line of character string from the keyboard.
int variable name= new java.util.Scanner(System.in).nextInt();
#Accepts the input of one integer from the keyboard.
-** if statement (conditional branch) **
java
if (Conditional expression) {
If the condition is true, the processing of this block works.
} else {
If the condition is false, the processing of this block works.
}
#Also, if statements are nested(Nested)can do.
if (Condition 1) {
Processing when true#If false, move to condition 2.
} else if (Condition 2) {
Processing when true#If false, move to condition 3.
} else if (Condition 3) {
Processing when true#If false, move to else processing.
} else {
Processing when all are false
}
-** switch statement **
java
switch (Variable name) {
case 〇〇:
Processing when the content of the variable is 〇〇
break;
case △△:
Processing when the content of the variable is △△
break;
case ××:
Processing when the content of the variable is XX
break;
default:
What to do if none of the cases apply(Can be omitted if not needed)
}
-The switch statement can only use an expression that compares whether the right side and the left side match. (<,>,! =, Etc. cannot be used)
-Can only be used with integers, strings, or characters to compare (decimal or boolean values cannot be used)
-Since the switch statement only jumps to the applicable case, if break is not described, the program will be read in sequence after jumping to a specific case.
-** while statement (repeated) **
java
while (Conditional expression) {
Processing when true#Loop forever until true.
}
-** for statement (repeat specified number of times) **
java
for (Initialization process,Repeat condition,Repeated processing) {
Repeated processing
}
#For example
for (int i = 0, i < 10, i++) {
System.out.println(i);
}
#The variable i is initialized and 0 is assigned. Process in the block until i is greater than 10.
#I every time processing++(Add 1 to the variable i)The process is performed.
What is a continue statement: The specified lap is interrupted and the next week is started.
Scope: The range in which variables can be used. Variables within a block can only be used within that block. (The scope of the variable is within that block)
Recommended Posts