大数加法 待完善

//邵文政20142894
import javax.swing.JOptionPane;
public class Bigintjiajian {
public static void main(String[]args)
{
    int length1,length2,j,k,a=0,e=0;
    String aa=new String();
    String firstnumber=JOptionPane.showInputDialog("请输入第一个大数");
    String secondnumber=JOptionPane.showInputDialog("请输入第二个  大    数");
    length1=firstnumber.length();
    length2=secondnumber.length();
 if(length1>length2)
 {
      a=length1;
 }
 else
 {
      a=length2;
      firstnumber=aa;
      firstnumber=secondnumber;
     secondnumber=aa;

  }
 char number[] =new char [a];
 char number1[]=new char [a];
 char number2[]=new char [a];
 e=a;
 for(int i=secondnumber.length();i>0;i--)
{
     number[a-1]=secondnumber.charAt(i-1);
     a--;
}
 for(int i=0;number[i]!=0;i++)
 {
      number[i]='0';
 }
 for(int i=firstnumber.length();i>0;i--)
{
       number1[e-1]=firstnumber.charAt(i-1);
       e--;
}
for(int i=firstnumber.length();i>0;i--)
{
      number2[i-1]=(char)(number[i-1]+number1[i-1]);
     if(number2[i-1]>=10)
    {
           number2[i-1]=(char) (number2[i]%10);
           j=number2[i-1]/10;
           number2[i-2]=(char) (number2[i-2]+j);
    }
}
  String message="0";
 for(int i=0;i<firstnumber.length();i++)
{

      message=message+" "+number2[i];
}
String title="计算结果";
JOptionPane.showConfirmDialog(null,
message, title,JOptionPane.CLOSED_OPTION);


 }

}

 

posted @ 2015-11-02 21:57  码农小正  阅读(130)  评论(0编辑  收藏  举报