==================================================================
这个代码应该没错,但是运行时间太长了,没等到结果。。。。。。
import java.math.BigInteger;
public class dishizhang {
public static void main(String[] args) {
// TODO Auto-generated method stub
int count = 0;
BigInteger n = new BigInteger(Long.MAX_VALUE + “”);
while (count < 5) {
if (isPrime(n)) {
System.out.print(n + " ");
count++;
}
n = n.add(BigInteger.ONE);
}
}
public static boolean isPrime(BigInteger i) {
for (BigInteger divisor1 = new BigInteger(“2”); divisor1
.compareTo(i.divide(new BigInteger(“2”))) <= 0; divisor1 = divisor1.add(BigInteger.ONE)) {
if (i.remainder(divisor1).compareTo(BigInteger.ZERO) == 0)
return false;
}
return true;
}
}
==================================================================
import java.math.BigInteger;
public class dishizhang {
public static void main(String[] args) {
System.out.println(“p\t2^p-1”);
for (int i = 1; i <= 100; i++) {
BigInteger mersenne = new BigInteger(index(i) + “”);
BigInteger b1 = new BigInteger(i + “”);
if (isMersennePrime(i) && isPrime(b1)) {
System.out.print(b1);
System.out.print(“\t”);
System.out.println(mersenne);
}
}
}
public static boolean isPrime(BigInteger b) {
boolean r = true;
BigInteger b2 = new BigInteger(2 + “”);
if (b.equals(b2))
r = true;
else if (b.equals(new BigInteger(1 + “”)))
r = false;
else {
for (; b.compareTo(b2) == 1; b2 = b2.add(BigInteger.ONE)) {
if ((b.mod(b2)).equals(new BigInteger(0 + “”))) {
r = false;
continue;
}
}
}
return r;
}
public static boolean isMersennePrime(int i) {
boolean r2 = false;
if (isPrime(index(i)))
r2 = true;
return r2;
}
public static BigInteger index(int i) {
BigInteger i1 = new BigInteger(1 + “”);
BigInteger i2 = new BigInteger(2 + “”);
for (int b = 1; b <= i; b++) {
i1 = i1.multiply(i2);
}
BigInteger f = i1.subtract(BigInteger.ONE);
return f;
}
}
==================================================================
import java.math.BigDecimal;
import java.math.BigInteger;
public class dishizhang {
public static void main(String[] args) {
dishizhang computeE = new dishizhang();
for (int i=100;i<=1000;i+=100){
computeE.ComputeE(i);
}
}
public static BigDecimal factorial(int number) {
BigDecimal result=BigDecimal.valueOf(1L);
if (number==1){
return result;
}else {
for (int i=1;i<=number;i++){
BigDecimal iVal=BigDecimal.valueOf(i);
result=result.multiply(iVal);
}
return result;
}
}
public BigDecimal ComputeE(int index) {
BigDecimal result=BigDecimal.valueOf(1);
for (int i=1;i<=index;i++){
BigDecimal one=new BigDecimal(1);
BigDecimal tem=one.divide(factorial(i),25,BigDecimal.ROUND_UP);
result=result.add(tem);
}
System.out.println(“i:”+index+" e= "+result.toString());
return result;
}
}
==================================================================
这个代码应该也没有错误,还是没有等到答案,可能是运行时间太长。
import java.math.BigInteger;
public class dishizhang {
public static void main(String[] args) {
// TODO Auto-generated method stub
BigInteger n = new BigInteger(Long.MAX_VALUE + “”);
int count = 0;
while (count < 10) {
if (divide(n)) {
System.out.print(n + " ");
count++;
}
n = n.add(BigInteger.ONE);
}
}
public static boolean divide(BigInteger i) {
BigInteger s1 = new BigInteger(5+“”);
BigInteger s2 = new BigInteger(6+“”);
BigInteger[] r1 = i.divideAndRemainder(s1);
BigInteger[] r2 = i.divideAndRemainder(s2);
if(r1[1]==BigInteger.ZERO && r2[1] == BigInteger.ZERO)
return true;
return false;
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
)]
[外链图片转存中…(img-gWitM5GK-1714851471509)]
[外链图片转存中…(img-V3clUUX6-1714851471509)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Android开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!