Skip to content

Instantly share code, notes, and snippets.

@mokomokohitsuzi
Created November 1, 2016 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mokomokohitsuzi/4c65dff91f8d3bc21615a9786dcdd345 to your computer and use it in GitHub Desktop.
Save mokomokohitsuzi/4c65dff91f8d3bc21615a9786dcdd345 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-8
import java.util.Scanner;
public class En4_8 {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
int n;
do {
System.out.print("整数値:");
n = stdIn.nextInt();
if (n <= 0) {
System.out.println("1以上の整数値を入力して下さい。");
}
} while (n <= 0);// nが0以下は弾く。
int x = n;
int count = 0;// 桁数カウント用
do {
x /= 10;// xが0未満になるまで、10で割り続ける。
count++;
} while (x > 0);
System.out.println("その値は" + count + "桁です。");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment