哪位大神能通俗易懂的解释下什么是算法,再回答这个问题?初学Java 对算法完全没有概念。
7 个解决方案
#1
顶一个
#2
他们的意思是让你用BigInteger去计算吧
#3
其实就是让你用 java.math.BigDecimal中的方法进行计算,具体代码如下,你可以试试:
package test;
import java.math.BigDecimal;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a = 12345678912345678912345678945d;
double b = 98765432198765432198765432165d;
BigDecimal b1 = new BigDecimal(a);
BigDecimal b2 = new BigDecimal(b);
System.out.println(b1.multiply(b2));
}
}
package test;
import java.math.BigDecimal;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a = 12345678912345678912345678945d;
double b = 98765432198765432198765432165d;
BigDecimal b1 = new BigDecimal(a);
BigDecimal b2 = new BigDecimal(b);
System.out.println(b1.multiply(b2));
}
}
#4
BigInteger number1 = new BigInteger("12345678912345678912345678945");
BigInteger number2 = new BigInteger("98765432198765432198765432165");
BigInteger result = number1.multiply(number2);
System.out.println(result);
BigInteger number2 = new BigInteger("98765432198765432198765432165");
BigInteger result = number1.multiply(number2);
System.out.println(result);
#5
试试这样:
package test;
import java.math.BigDecimal;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a = 12345678912345678912345678945d;
double b = 98765432198765432198765432165d;
BigDecimal b1 = new BigDecimal("12345678912345678912345678945");
System.out.println(b1);
BigDecimal b2 = new BigDecimal("98765432198765432198765432165");
System.out.println(b2);
System.out.println(b1.multiply(b2));
}
}
#6
非常感谢楼上各位的解答,以前从来没有关注过BigInteger和BigDecimal这两个类...
#7
如果用已有类BigInteger和BigDecimal那就不叫用算法计算两个数的积了. 面试遇到这种情况要有自己的见解, 就算你使用小学时学的乘法口决来计算也可以的.
#1
顶一个
#2
他们的意思是让你用BigInteger去计算吧
#3
其实就是让你用 java.math.BigDecimal中的方法进行计算,具体代码如下,你可以试试:
package test;
import java.math.BigDecimal;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a = 12345678912345678912345678945d;
double b = 98765432198765432198765432165d;
BigDecimal b1 = new BigDecimal(a);
BigDecimal b2 = new BigDecimal(b);
System.out.println(b1.multiply(b2));
}
}
package test;
import java.math.BigDecimal;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a = 12345678912345678912345678945d;
double b = 98765432198765432198765432165d;
BigDecimal b1 = new BigDecimal(a);
BigDecimal b2 = new BigDecimal(b);
System.out.println(b1.multiply(b2));
}
}
#4
BigInteger number1 = new BigInteger("12345678912345678912345678945");
BigInteger number2 = new BigInteger("98765432198765432198765432165");
BigInteger result = number1.multiply(number2);
System.out.println(result);
BigInteger number2 = new BigInteger("98765432198765432198765432165");
BigInteger result = number1.multiply(number2);
System.out.println(result);
#5
试试这样:
package test;
import java.math.BigDecimal;
public class test2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double a = 12345678912345678912345678945d;
double b = 98765432198765432198765432165d;
BigDecimal b1 = new BigDecimal("12345678912345678912345678945");
System.out.println(b1);
BigDecimal b2 = new BigDecimal("98765432198765432198765432165");
System.out.println(b2);
System.out.println(b1.multiply(b2));
}
}
#6
非常感谢楼上各位的解答,以前从来没有关注过BigInteger和BigDecimal这两个类...
#7
如果用已有类BigInteger和BigDecimal那就不叫用算法计算两个数的积了. 面试遇到这种情况要有自己的见解, 就算你使用小学时学的乘法口决来计算也可以的.