1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Java 基本の基本3

Last updated at Posted at 2022-12-02

はじめに

自身でprogataやスクールでJavaを勉強中。学んだことをアウトプットして、より定着させるために記事にまとめていきます。継続は力なり!

演算子

四則演算や値の比較などの演算を行うための記号。

算術演算子

int num1 = 20;
int num2 = 5;

num1 + num2 //加算
//演算結果 25

num1 - num2 //減算
//演算結果 15

num1 * num2 //積算
//演算結果 100

num1 / num2 //除算
//演算結果 4

num1 % num2 //余剰
//演算結果 0

文字列結合演算子

String firstName = "Toro";
String lastnName = "Yamada ";

String fullName = lastName + firstName;
//演算結果 "Yamada Toro"

代入演算子

int num1 = 10;
int num2 = 5;

num1 = num1 + num2 //10 + 5をして、num1に代入する。つまり15
//右側を省略して書く。
num1 += num2; // 15
num1 -= num2; // 10
num1 *= num2; // 50
num1 /= num2; // 10

インクリメント演算子、デクリメント演算子

int num1 = 10;
int num2 = 5;

num1++; //11 インクリメント→1を加算
num2--; //4  デクリメント→1を減算
num1 = ++num2; //num1=5, num2=5  インクリメントをしてから代入
num1 = num2++; //num1=5, num2=6  代入してからインクリメント
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?