判斷一個數能被幾個9整除

題目:判斷一個數能被幾個9整除。

import java.util.Scanner;
public class Prog45{
	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整除。");
	}
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章