株式会社Electoria

【Dart】式と演算子

【Dart】式と演算子
式と演算子
開発環境
算術演算子
+などの計算に用いるを記号を算術演算子と言います。
Dartの算術演算子は下表のような種類があります。
算術演算子 処理
+ 足し算 1+2
引き算 2-1
一例として、下のコードを起動してください。足し算の時と同様、様々な計算ができます。
void main() {
  print(1 + 2); //足し算
  print(2 - 1); //引き算
  print(2 * 3); //掛け算
  print(5 / 2); //割り算
  print(5 ~/ 2); //割り算(整数、少数以下切り捨て)
  print(5 % 2); //割り算のあまり(剰余)
}
式を記述する時に足し算よりも掛け算を優先するという一般的なルールがあります。それはDartも同様です。下のコードを起動してください。
void main() {
  print(1 + 2 * 3); //後の掛け算が優先される
  print((1 + 2) * 3); //優先順を変更するには()を付ける
}
一般的なルールと同様、足し算(+)や引き算(-)よりも、掛け算(*)や割り算(/, ~/, %)の方が優先順位は高いです。
  • Comments ( 4 )
  • Trackbacks ( 0 )
  1. Hi there! This article couldn’t be written much better!

    Going through this article reminds me of my previous roommate!
    He continually kept talking about this. I most certainly
    will forward this article to him. Fairly certain he will
    have a great read. I appreciate you for sharing!

  2. Excellent post! We are linking to this particularly
    great article on our site. Keep up the good writing.

  3. Hi, i feel that i saw you visited my site thus i came to return the want?.I’m attempting to to find things to improve my website!I guess its ok to make use of some of your ideas!!

  4. What i do not understood is if truth be told how you’re no longer
    really a lot more neatly-preferred than you might be now.
    You’re very intelligent. You know therefore considerably in relation to this topic, made me for
    my part consider it from so many numerous angles. Its
    like women and men aren’t interested unless it is one thing to do with Woman gaga!
    Your own stuffs nice. All the time maintain it up!

Leave A Reply

*
*
* (公開されません)