Program flow
--The extension of the java file will be .java.
name of the class.java
public class class name{
public static void method name(String[] args) {
//processing
}
}
The inside of a class is called a class block, and the inside of a method is called a method block.
Output the value taken as an argument.
python
Data type variable name;
//For example
int age; //Declare the variable first.
age = 30; //Next, assign the data to the variable.
You can also declare and assign variables at the same time. (Called variable initialization)
python
Data type variable name=value;
//For example
int age = 30;
Classification | Model name | Data to store | Example |
---|---|---|---|
integer | long | 大きなinteger | long worldPeople; //World population |
int | Ordinary integer | int salary; //Salary amount | |
short | Small integer | short age; //age | |
byte | Smaller integer | byte glasses; //Number of glasses you have | |
a few | double | Ordinary decimal | double pi; //Pi |
float | Decimal numbers that can be a little vague | float weight//body weight | |
Boolean value | boolean | true or false | boolean isMarried;//Whether you are married or not |
letter | char | 1つのletter | char initial; //イニシャル1letter |
String | String | Character sequence | String name; //My name |
python
age = 20 + 5; //Operator=Or+以外のageOr20、5(変数Or値のこと)Is called the operand.
//All formulas consist only of these two elements.
Among the operands, the values assigned to variables and the values of numbers, characters, and character strings described in the source code are called literals. Each literal has a data type.
--Assignment operator
python
a = 10; // =>10,Substitute the right side for the left side
a += 10; // =>a = a +10. When the left side and the right side are added and assigned to the left side, and the characters are added, the left side and the right side are connected.
a -= 10; // =>a = a -10. Subtract the left and right sides and substitute for the left side
a *= 10; // =>a = a *10. Multiply the left side and the right side and substitute for the left side
a /= 10; // =>a = a /10. Divide the left and right sides and substitute for the left side
a %= 10; // =>a = a %10. Divide the left and right sides and substitute the remainder for the left side
--Increment decrement operator
python
a++(Or++a); // =>a +1, only 1 is added to a.
a--(Or--a); // =>a -1, only 1 is subtracted for a.
Variables can be overwritten. However, since the tax rate and the circumference rate are basically the same, it would be troublesome if they could be overwritten. Therefore, such variables are assigned as constants.
python
Data type constant name=value;
final int PRICE = 100;
//Constant names are generally capitalized
Recommended Posts