/*
2017年3月13日10:28:21
java基礎50道經典練習題 例45
Athor: ZJY
Purpose:
【程序45】
題目:判斷一個素數能被幾個9整除
*/
import java.util.Scanner;
public class ProgramNo45_1
{
public static void main(String[] args) {
System.out.print("請輸入一個數: ");
Scanner sc = new Scanner(System.in);
long number = sc.nextLong();
sc.close();
int count = 0;
long number_buf = number;
while (number_buf >= 9) {
number_buf /= 9;
count++;
}
System.out.println(number+"最多能被"+count+"個9除");
}
}
/*
2017年3月13日10:28:21
java基礎50道經典練習題 例45
Athor: ZJY
Purpose:
*/
import java.util.Scanner;
public class ProgramNo45_2
{
public static void main(String[] args){
System.out.print("請輸入一個數:");
Scanner scan = new Scanner(System.in);
long l = scan.nextLong();
long n = l;
scan.close();
int count = 0;
while(n > 8){
n /= 9;
count++;
}
System.out.println(l+"能被"+count+"個9整除。");
}
}