Java control syntax

** What I learned today **

Instruction execution statement

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.

Typical control syntax

-** 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.

Recommended Posts

Java control syntax
Java control syntax
[Java] Control syntax notes
[Java] Summary of control syntax
Control syntax operator
Organized memo in the head (Java --Control syntax)
Java version control on macOS
Java basic syntax + α trap
[Java] Multi-thread processing --Exclusive control
Version control Java with SDKMAN
I touched Scala ~ [Control syntax] ~
Java study # 7 (branch syntax type)
Java version control with jenv
Java
☾ Java / Iterative statement and iterative control statement
Java
Java review ③ (control syntax [if / switch / while / for], conditional expression)
Syntax examples often used in Java
[Java] Object-oriented syntax --class method / argument
[ev3 × Java] Display, sound, LED control
Notes on signal control in Java
[ev3 x Java] Single motor control
Studying Java ―― 3
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Studying Java ―― 9
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Java string
java (array)
Java static
Java serialization
java beginner 4
JAVA paid
Studying Java ―― 4
Java (set)
java shellsort
[Java] compareTo
Studying Java -5
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
Studying Java ―― 1
[Java] Array
[Java] Polymorphism
Studying Java # 0
Java review
java framework