Studying Java ①

Since I started studying Java, I will leave what I learned.

Output

System.out.println("Hello World!");
System.out.println(123);

//Execution result
//Hello World!
//123

Output in () and start a new line. How to read println is print line. I tried to find out what System and out mean, but for now I decided not to go deep. Reference) Understand System.out.println ("hello, world")

Variable declaration

int number; //Declare variable number of type int
String str; //Declare a variable str of type String

Variable initialization

int number = 5;
String str = "hoge";

Assign a value at the same time as the variable is declared.

Variable calculation, concatenation

//Calculation of int type variables
int number1 = 3;
System.out.println(number1 + 5);   //The result is 8
int number2 = 10;
System.out.println(number1 + number2);   //The result is 13

//Concatenation of String type variables
String greeting = "Good morning";
System.out.println(greeting + "sky");   //おはようsky
String name = "Riku";
System.out.println(greeting + name);   //Good morning Riku

Self-substitution

x = x + 10;   //Add 10 to the variable x and overwrite

There are basic and abbreviations for the description method.

Uninflected word Abbreviation
x = x + 10 x += 10
x = x - 10 x -= 10
x = x * 10 x *= 10
x = x / 10 x /= 10
x = x % 10 x %= 10

When adding and subtracting only 1

There are also abbreviations.

Uninflected word Abbreviation Further omitted
x = x + 1 x += 1 x++
x = x - 1 x -= 1 x--

double type

There are several data type variables that handle values other than int type. Reference) Java Road: Variables (1. Variables) The double type handles values with a decimal point.

double number = 3.14;
System.out.println(number);   ///The result is 3.14

Recommended Posts

Studying Java ―― 3
Studying Java ―― 9
Studying Java ―― 4
Studying Java -5
Studying Java # 0
Studying Java ②
Studying Java ―― 7
Studying Java ―― 2
Studying Java ①
Studying Java -10
Studying Java 8 (Optional)
Studying java9 (jShell)
Studying Java 8 (Stream)
Studying Java 8 (Collector / Collectors)
Studying Java 8 (see method)
Java
Studying Java ~ Part 8 ~ Cast
Java
Java learning (0)
[Java] array
Java protected
[Java] Annotation
[Java] Module
Java array
Java scratch scratch
Java tips, tips
Java methods
Java method
java (constructor)
Java array
java (override)
java (method)
Java Day 2018
Java string
Studying Java # 6 (How to write blocks)
Java static
Java serialization
java beginner 4
JAVA paid
Java (set)
[Java] compareTo
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
Java array
[Java] Array
Java review
java framework
Java features
[Java] Inheritance
FastScanner Java
Java features
java beginner 3
Java memo
Java inheritance
[Java] Overload
Java basics
[Java] Annotation
java beginner
Java (add2)