[JAVA] About for statement and if statement

Processing using if syntax A function to use when you want to execute a process when a certain condition is met. The basic writing method is as follows

if (condition) { What you want to do if true }

You can also set the processing when false. In that case,

if (condition) { What you want to do if true }else{ Process you want to execute when false }

for statement Iterative processing is possible. The basic writing method is as follows

for (initial value; condition range; change expression) { Content you want to process repeatedly }

Code reflections

I wrote the following code in the process of the task of squared only even numbers. ↓ for(i = 0; i <= 20; i++){ if(i % 2 == 0){ System.out.printf("%d * %d = %d", i, i, i*i).println(); }} 0 * 0 = 0 2 * 2 = 4 4 * 4 = 16 6 * 6 = 36 8 * 8 = 64 10 * 10 = 100 12 * 12 = 144 14 * 14 = 196 16 * 16 = 256 18 * 18 = 324 20 * 20 = 400

Originally, the following contents are sufficient for(i = 0; i <= 20; i+=2){ System.out.printf("%d * %d = %d", i, i, i*i).println(); } 0 * 0 = 0 2 * 2 = 4 4 * 4 = 16 6 * 6 = 36 8 * 8 = 64 10 * 10 = 100 12 * 12 = 144 14 * 14 = 196 16 * 16 = 256 18 * 18 = 324 20 * 20 = 400

Allows you to write with optimized code.

Main code I wrote in the exercise today スクリーンショット 2020-04-10 23.18.37.png スクリーンショット 2020-04-11 1.37.01.png スクリーンショット 2020-04-11 1.37.12.png スクリーンショット 2020-04-11 1.37.21.png

Recommended Posts

About for statement and if statement
About if statement and branch processing
About Ruby if statement
Points for refactoring (if statement)
if statement
Java for statement
Basics of java basics ② ~ if statement and switch statement ~
Compare the speed of the for statement and the extended for statement.
[For beginners] About lambda expressions and Stream API
[Java] for statement, while statement
Complex for statement (basic)
[Java] for statement / extended for statement
About Bean and DI
About classes and instances
About gets and gets.chomp
About redirect and forward
10 Corresponds to if statement
Studying Java-Part 10-if statement
(Memo) Java for statement
About encapsulation and inheritance
hash and each statement
About Serializable and serialVersionUID
About products using crud processing and devise (for beginners)
About a double loop that puts a For statement inside a For statement
About RSpec directory structure and role for each spec
[Swift] Use for where rather than nesting for and if
Store in Java 2D map and turn with for statement
[Java] Make variables in extended for statement and for Each statement immutable
About synchronized and Reentrant Lock
[Java] Basic statement for beginners
Java if and switch statements
Let's understand the if statement!
About Ruby hashes and symbols
[Java] About String and StringBuilder
About the same and equivalent
Scheduler for RxAndroid and RxSwing
☾ Java / Iterative statement and iterative control statement
About classes and instances (evolution)
About pluck and ids methods
Consideration about classes and instances
[Ruby] problem with if statement
About Java Packages and imports
About Ruby and object model
About Popover fix for iOS 13
About Ruby classes and instances
About instance variables and attr_ *
About self-introduction and common errors
Java while and for statements
[Ruby] conditional branch if statement
[Swift] Use for where rather than nesting for and if
Creating a mixed conditional expression of Rails if statement and unless
About C # lambda expressions and Linq
Find out about annotationProcessor for Gradle 5.0
About Java static and non-static methods
[Android] Cause and remedy for TransactionTooLargeException
AWS SDK for Java 1.11.x and 2.x
About fastqc of Biocontainers and Java
Java for beginners, expressions and operators 1
Learn more about gems and bundlers
[Ruby] present/blank method and postfix if.
About the equals () and hashcode () methods