/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package BiDemo;/**
*
* @author hhz
*/
public class javaBig4 {
//将输入进来的字符串转换为int数组。
public static int[] returnArray(String Big){
int Biglength = Big.length();
int [] Array = new int[Biglength];
for(int i = 0 ;i <=Biglength - 1;i++){
Array[i] = Integer.parseInt(Big.substring(i,i+1));
}
return Array;
}//
public static String chengfa(String first,String second)
{
int longfirst = first.length();
int longsecond = second.length();
int longfs = longfirst+longsecond;
int [] Intfirst = returnArray(first);
int [] Intsecond = returnArray(second);
int [][] result = new int[longsecond][longfs]; //用来存两个数相乘的结果。
int [] addresult = new int[longfs]; //用来存result数组中同列不同行的数据相加的值。
String endresult="";
int add = 0; //初始化result数组的值为零
for(int i=0; i<=longsecond-1;i++){
for(int j=0;j<=longfs-1;j++){
result[i][j]=0;
}
}//
//将first和second 两数相乘的值存放到数组result中。
for(int i=longsecond-1;i>=0;i--){
for(int j=longfirst-1;j>=0;j--){
result[longsecond-i-1][j+i-1]=Intfirst[j]*Intsecond[i];
}
}//
//将result数组中同列不同行的各个数相加。
for(int i=longfs-1;i>=0;i--){
for(int j=0;j<longsecond-1;j++ ){
addresult[i] += result[j][i];
}
}//
//将addresult数组中个元素进行相加,进位,得出为字符串的结果。
for(int i=longfs-1;i>=0;i--){
int a = (addresult[i]+add)%10; //得出各个余数。 int b = (addresult[i]+add)/10; //得出各个商的值。 //判断b的值,并重新给add赋值。
endresult += a;
if(b>0){
add=b;
}// }
return endresult;
}
public static void main(String args[]){
System.out.println(returnArray("5785"));
}}在我电脑上netbeans的运行结果是:run:
[I@de6ced
成功生成(总时间:1 秒)
本人菜鸟,希望各位不吝赐教。
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package BiDemo;/**
*
* @author hhz
*/
public class javaBig4 {
//将输入进来的字符串转换为int数组。
public static int[] returnArray(String Big){
int Biglength = Big.length();
int [] Array = new int[Biglength];
for(int i = 0 ;i <=Biglength - 1;i++){
Array[i] = Integer.parseInt(Big.substring(i,i+1));
}
return Array;
}//
public static String chengfa(String first,String second)
{
int longfirst = first.length();
int longsecond = second.length();
int longfs = longfirst+longsecond;
int [] Intfirst = returnArray(first);
int [] Intsecond = returnArray(second);
int [][] result = new int[longsecond][longfs]; //用来存两个数相乘的结果。
int [] addresult = new int[longfs]; //用来存result数组中同列不同行的数据相加的值。
String endresult="";
int add = 0; //初始化result数组的值为零
for(int i=0; i<=longsecond-1;i++){
for(int j=0;j<=longfs-1;j++){
result[i][j]=0;
}
}//
//将first和second 两数相乘的值存放到数组result中。
for(int i=longsecond-1;i>=0;i--){
for(int j=longfirst-1;j>=0;j--){
result[longsecond-i-1][j+i-1]=Intfirst[j]*Intsecond[i];
}
}//
//将result数组中同列不同行的各个数相加。
for(int i=longfs-1;i>=0;i--){
for(int j=0;j<longsecond-1;j++ ){
addresult[i] += result[j][i];
}
}//
//将addresult数组中个元素进行相加,进位,得出为字符串的结果。
for(int i=longfs-1;i>=0;i--){
int a = (addresult[i]+add)%10; //得出各个余数。 int b = (addresult[i]+add)/10; //得出各个商的值。 //判断b的值,并重新给add赋值。
endresult += a;
if(b>0){
add=b;
}// }
return endresult;
}
public static void main(String args[]){
System.out.println(returnArray("5785"));
}}在我电脑上netbeans的运行结果是:run:
[I@de6ced
成功生成(总时间:1 秒)
本人菜鸟,希望各位不吝赐教。
public static void main(String args[]) {
StringBuffer _result = new StringBuffer();
for (int element : returnArray("5785")) {
if (_result.equals(""))
_result.append(element);
else {
_result.append("\t" + element);
}
}
System.out.println(_result);
}
public class javaBig4 {
//将输入进来的字符串转换为int数组。
public static int[] returnArray(String Big){
int Biglength = Big.length();
int [] Array = new int[Biglength];
for(int i = 0 ;i <=Biglength - 1;i++){
Array[i] = Integer.parseInt(Big.substring(i,i+1));
}
return Array;
}//
public static String chengfa(String first,String second)
{
int longfirst = first.length();
int longsecond = second.length();
int longfs = longfirst+longsecond;
int [] Intfirst = returnArray(first);
int [] Intsecond = returnArray(second);
int [][] result = new int[longsecond][longfs]; //用来存两个数相乘的结果。
int [] addresult = new int[longfs]; //用来存result数组中同列不同行的数据相加的值。
String endresult="";
int add = 0;
int t = 0 ;
//初始化result数组的值为零
for(int i=0; i<=longsecond-1;i++){
for(int j=0;j<=longfs-1;j++){
result[i][j]=0;
}
}//
//将first和second 两数相乘的值存放到数组result中。
for(int i=longsecond-1;i>=0;i--){
for(int j=longfirst-1;j>=0;j--,t++){
result[longsecond-i-1][longfs-t+j-longfirst]=Intfirst[j]*Intsecond[i];
}
}//
//将result数组中同列不同行的各个数相加。
for(int i=longfs-1;i>=0;i--){
for(int j=0;j<longsecond-1;j++ ){
addresult[i] += result[j][i];
}
}//
//将addresult数组中个元素进行相加,进位,得出为字符串的结果。
for(int i=longfs-1;i>=0;i--){
int a = (addresult[i]+add)%10; //得出各个余数。 int b = (addresult[i]+add)/10; //得出各个商的值。 //判断b的值,并重新给add赋值。
endresult += a;
if(b>0){
add=b;
}// }
return endresult;
} public static void main(String args[]) {
System.out.println(chengfa("44121","34633"));
}
}计算大整数的乘法,麻烦看看。