0
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?

今回は paiza の「インクリメント」の問題に挑戦!

専門用語がでてきて難しそうけど、やってることは簡単!


問題概要

  • 整数 n が1つ入力される。

  • その値に 1 を足した結果 を出力する。


入力例:

1

出力例:

2






✅ OK例:

const fs = require("fs");

const input = fs.readFileSync("/dev/stdin", "utf-8");

const n = Number(input);
console.log(n + 1);




別解:一行で書く

console.log(+require("fs").readFileSync(0) + 1);
  • + は単項プラス演算子(数値変換)
  • 読みやすさは落ちるけど、「最小コード」を狙うならこういう書き方もある。






🗒️ 「インクリメント」

🔍 インクリメントとは → 「値を1だけ増やす操作」。

◯ プログラミングでよく使う記号 →

  • n = n + 1
  • n += 1
  • n++

例:

let x = 5;
x++;      // 6
x += 1;   // 7
x = x+1;  // 8

この問題では n + 1 という形で インクリメントの基本 を学ぶのが目的かな。




僕の失敗談(´;ω;`)と解決法🐈

0
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
0
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?