博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
机试题:大整数的因子
阅读量:4107 次
发布时间:2019-05-25

本文共 1086 字,大约阅读时间需要 3 分钟。

以为很简单,第一遍

import java.util.Scanner;public class D_4_1_1 {	public static void main(String[] args) {		// TODO Auto-generated method stub		Scanner sc=new Scanner(System.in);		while(sc.hasNext())		{			int c=sc.nextInt();			boolean has=false;			for(int k=2;k<=9;k++)			{				if(c%k==0)				{		System.out.print(k+" ");				has=true;				}			}			if(has==false)				System.out.println("none");		}	}}

结果

看了通过的代码

这是一道大数的题,改成biginteger的

在踩了好多坑之后。终于

import java.math.BigInteger;import java.util.Scanner;public class D_4_1_2 {	public static void main(String[] args) {		// TODO Auto-generated method stub		String str;		Scanner sc=new Scanner(System.in);		while(sc.hasNext()) {			str=sc.next();			BigInteger bi=new BigInteger(str);			BigInteger i=new BigInteger("2");			BigInteger j=new BigInteger("9");			BigInteger t=new BigInteger("1");			BigInteger zero=new BigInteger("0");			boolean flag=false;			while(!(i.subtract(j).equals(t)))			{				if(bi.mod(i).equals(zero))				{					flag=true;					System.out.print(i+" ");				}				i=i.add(t);			}			if(flag==false)			{				System.out.println("none");			}		}	}}

 

转载地址:http://wjssi.baihongyu.com/

你可能感兴趣的文章
VUe+webpack构建单页router应用(一)
查看>>
Node.js-模块和包
查看>>
实现接口创建线程
查看>>
JavaScript实现页面无刷新让时间走动
查看>>
CSS实例:Tab选项卡效果
查看>>
前端设计之特效表单
查看>>
Java的时间操作玩法实例若干
查看>>
JavaScript:时间日期格式验证大全
查看>>
解决SimpleDateFormat线程安全问题NumberFormatException: multiple points
查看>>
处理Maven本地仓库.lastUpdated文件
查看>>
计算机网络-OSI各层概述
查看>>
Java--String/StringBuffer/StringBuilder区别
查看>>
分布式之redis复习精讲
查看>>
(python版)《剑指Offer》JZ01:二维数组中的查找
查看>>
(python版)《剑指Offer》JZ06:旋转数组的最小数字
查看>>
(python版)《剑指Offer》JZ13:调整数组顺序使奇数位于偶数前面
查看>>
(python版)《剑指Offer》JZ28:数组中出现次数超过一半的数字
查看>>
(python版)《剑指Offer》JZ30:连续子数组的最大和
查看>>
(python版)《剑指Offer》JZ02:替换空格
查看>>
使用JSTL
查看>>