Created
November 1, 2016 13:19
-
-
Save mokomokohitsuzi/4c65dff91f8d3bc21615a9786dcdd345 to your computer and use it in GitHub Desktop.
新・明解Java入門 演習4-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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