This article was written in Previous article,
** 2nd day of article posting every day for 7 days **
It has become
The code to use is pasted below, but see the previous article for more details on the features of this app!
--java version: https://github.com/sato-na/guruwake_java
--kotlin version: https://github.com/sato-na/guruwake_kotlin
↓ This is the main subject of this article ↓
-- table of contents --
How to define variables
How to write an if statement
How to write a for statement
How to change from String to Int
--For java
Type variable name=initial value;
Type must be specified
Example)
ResultActivty.java
String rTxt = ""; //31st line
int memberNum = memberL.size(); //Line 33
--For kotlin
val/var variable name=initial value
It is necessary to specify val (immutable) or var (variable)
Example)
ResultActivity.kt
var rTxt = "" //Line 22
val memberNum = memberL.size //24th line
--For java
if (conditions) {
//Processing when the condition is true
}
Example)
ResultActivity.java
if (n <= memberNum % groupNumI) { //39th line
p++;
}
--For kotlin
if (conditions) {
//Processing when the condition is true
}
Example)
ResultActivity.kt
if (n <= memberNum % groupNumI) { //30th line
p++
}
Same way of writing
--For java
for (Variables used when turning the for statement;Variable condition;Processing of variables after processing) {
//Processing when entering a for statement
}
Example)
ResultActivity.java
for (int q = 0; q < p; q++) { //Line 43
rTxt += " " + memberL.get(0) + "\n";
memberL.remove(0);
}
--For kotlin
for (Variable used in for In Initial value of variable..Final value){
//Processing when entering a for statement
}
Example)
ResultActivity.kt
for (q in 0..p-1) { //Line 34
rTxt += " " + memberL[0] + "\n"
memberL.remove(memberL[0])
}
The method of specifying the number of for statements is different
--For java
int variable= Integer.parseInt(String to change)
Example)
ResultActivity.java
final String groupNum = intent.getStringExtra("GROUP_NUM"); //26th line
int groupNumI = Integer.parseInt(groupNum); //32nd line
--For kotlin
val/var variable name: Int =Value to change.toInt()
Example)
ResultActivity.kt
val groupNum = intent.getStringExtra("GROUP_NUM") //18th line
val groupNumI : Int = groupNum.toInt() //Line 23
The syntax is very different
This time I tried to summarize the basics of java and kotlin. I'm only using what's in the code on github, so Variable names are difficult to understand, and there are many functions not mentioned in this article. Maybe it was hard to understand ... However, I hope it's a little easier to understand than just the code.
I will post an article like this tomorrow, so please keep an eye on me.
Recommended Posts