• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
???!!!
博客园    首页    新随笔    联系   管理    订阅  订阅
java基础练习 18
import java.util.Scanner;
public class Eightheen {
/*判断一个素数能被几个9整除*/
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.println("请输入一个素数:");
int a=input.nextInt();
int b=9,i=0;
if(judge(a)==0){
while(b%a!=0){
b=b*10+9;
i++;
}
System.out.println(a+"能被"+i+"个9整除");
}
else
System.out.println(a+"不是素数");


}
public static int judge(int x){
int i,flag=0;
for(i=2;i<x/2;i++)
if(x%i==0){
flag=1;
break;
}
return flag;
}

}

  

posted on 2017-01-26 23:30  ???!!!  阅读(220)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3