bu program ıle ıstedıgınız basamak uzunlugunda(1000,2000 farketmez) ıkı sayıyı carpabılırsınız.
Kod:
import javax.swing.*;
public class Carpma
{
public static void main (String[] args)
{
int atHand=0, digit1=0, digit2=0, digitNew=0;
String Number1;
String Number2;
Number1=JOptionPane.showInputDialog("enter a number");
Number2=JOptionPane.showInputDialog("enter a number");
int length1=Number1.length();
int length2=Number2.length();
for(;length1>length2
{
Number2="0"+Number2;
length2++;
}
for(;length1{
Number1="0"+Number1;
length1++;
}
int k=0;
int i=length2-1;
String satir[]=new String[length2];
for(int h=0;hsatir[h]="";
while (i>=0) {
digit2=((new Integer(Number2.charAt(i))).intValue()) -48;
atHand=0;
for(int j=length2-1;j>=0;j--){
digit1=((new Integer(Number1.charAt(j))).intValue())-48 ;
digitNew=(atHand+(digit1*digit2)) %10;
atHand=(digit1*digit2+atHand) / 10 ;
satir[k]=digitNew+satir[k];
if(atHand!=0 && j==0){
satir[k]=atHand+satir[k];
}
}//for
i--; k++;
} //while
for(int b=0;b{
if(b!=0)
for(int m=0;msatir[b]=satir[b]+"0";
}
for(int b=0;bsatir[b+1]=topla(satir[b],satir[b+1]);
JOptionPane.showMessageDialog(null,satir[length2-1]);
}
static String topla (String Number1 , String Number2){
int atHand=0, digit1=0, digit2=0, digitNew=0;
int length1=Number1.length();
int length2=Number2.length();
for(;length1>length2
{
Number2="0"+Number2;
length2++;
}
for(;length1{
Number1="0"+Number1;
length1++;
}
int i=length2-1;
String sum="";
while (i>=0) {
digit1=((new Integer(Number1.charAt(i))).intValue()) -48;
digit2=((new Integer(Number2.charAt(i))).intValue())-48 ;
digitNew=(atHand+digit1+digit2) %10;
atHand=(digit1+digit2+atHand) / 10 ;
sum=digitNew+sum;
--i;
}
if(atHand!=0)
sum=atHand+sum ;
return sum;
}
}//class