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?

More than 5 years have passed since last update.

乱数で出力した数値の桁数の求め方

Posted at
public static void main(String args[]) {
	Random random = new Random();
	int num = random.nextInt(10000)+1;
	int valLen = String.valueOf( num ).length();
	System.out.println(num + "の桁数は" + valLen);
}

}

このコードは1以上1000未満の数値をランダムに出力する
String.ValueOf()メソッドを使うことで数値から文字列へ変換し、.lenghtで
文字化した数値の桁数を測る

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?