Since I started studying Java, I will leave what I learned.
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")
int number; //Declare variable number of type int
String str; //Declare a variable str of type String
int number = 5;
String str = "hoge";
Assign a value at the same time as the variable is declared.
//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
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 |
There are also abbreviations.
Uninflected word | Abbreviation | Further omitted |
---|---|---|
x = x + 1 | x += 1 | x++ |
x = x - 1 | x -= 1 | x-- |
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