i am trying to remove the dialog boxes (JOptionPane) and replace them with a simple scanner scan= new Scanner (System.in) but i just keep cconfusing myself with the adding of things and removal of things. could anyone help me out? here is my code.


import java.util.Scanner;

import javax.swing.JOptionPane;
class hugeint
{
int a[]=new int[40];
int b[]=new int[40];
int p[]=new int[40];
int nofd,x,y=0,q,z=0,n=0;
Scanner scan = new Scanner (System.in);
void inputhugeint()
{

String st;

System.out.println ("Enter a huge value: ");
st = scan.toString();
st=JOptionPane.showInputDialog("Enter any hugeint: ");
int i,n;
n=st.length();
for (i=0; i<n; i++)
a[i]=(st.charAt(n-i-1)-48);
nofd=n;
}

void outputhugeint()
{
String st="";
//int i;
if (y==1)
st="- ";
if(y==0)
st="";
for (int i=x-1; i>=0; i--)
st=st+b[i];
JOptionPane.showMessageDialog(null,st);
}

void addhugeint(hugeint ob)
{
int i,carry=0,sum;
for (i=0; i<nofd && i<ob.nofd; i++)
{
sum=(a[i]+ob.a[i]+carry);
b[i]=sum%10;
carry=sum/10;
}
for ( ; i<nofd; i++)
{
sum=a[i]+carry;
b[i]=sum%10;
carry=sum/10;
}
for ( ; i<ob.nofd; i++)
{
sum=ob.a[i]+carry;
b[i]=sum%10;
carry=sum/10;
}
if (carry>0)
{
b[i]=carry;
i++;
}
y=0;
x=i;
}
boolean check( int s[],int n[])
{
int i;//,borrow=0,sub;
if(nofd<q)
return true;
else if(nofd==q)
{
for(i=nofd-1;i>=0;i--)
{
if(s[i]>n[i])
return false;
else if(s[i]<n[i])
return true;
z=1;
}
}
return false;
}

void subhugeint(hugeint ob)
{
int i,borrow=0,sub;
q=ob.nofd;
for(i=0;i<ob.nofd;i++)
p[i]=ob.a[i];
y=0;
if(check(a,p))
{
n=1;
for(i=0;i<nofd;i++)
{
p[i]=a[i];
a[i]=ob.a[i];
ob.a[i]=p[i];
}
while(i<ob.nofd)
a[i]=ob.a[i++];
x=ob.nofd;
ob.nofd=nofd;
nofd=x;
y=1;
}
for (i=0;i<ob.nofd; i++)
{
sub=a[i]-ob.a[i]-borrow;
if (sub<0)
{
sub+=10;
borrow=1;
}
else
borrow=0;
b[i]=sub;
}

while (borrow>0&& i<nofd)
{
sub=a[i]-borrow;
if (sub<0)
{
sub+=10;
borrow=1;
}
else
borrow=0;
b[i++]=sub;
}
while(i<nofd)
b[i]=a[i++];
while(b[i-1]==0 && i>1)
i--;
x=i;
}
boolean isEqualTo(hugeint ob)
{
boolean test=true;
for (int i=0; i<nofd||i<ob.nofd; i++)
if (a[i]!=ob.a[i])
test=false;
return test;
}

boolean isNotEqualTo(hugeint ob)
{
for (int i=0; i<nofd; i++)
if (a[i]!=ob.a[i])
return true;
return false;
}

boolean isGreaterThan(hugeint ob)
{
int i;
q=ob.nofd;
for(i=0;i<ob.nofd;i++)
p[i]=ob.a[i];
if(check(a,p))
return false;
return true;
}

boolean isLessThan(hugeint ob)
{
int i;
q=ob.nofd;
for (i=0;i<ob.nofd;i++)
p[i]=ob.a[i];
if(!check(a,p))
return false;
return true;
}

boolean isGreaterThanOrEqualTo(hugeint ob)
{
if (nofd>ob.nofd)
return true;
else if (nofd<ob.nofd)
return false;
else
for (int i=nofd-1; i>=0; i--)
if (a[i]<ob.a[i])
return false;
else if(a[i]>ob.a[i])
return true;
return true;
}

boolean isLessThanOrEualTo(hugeint ob)
{
if (nofd<ob.nofd)
return true;
else if (nofd>ob.nofd)
return false;
else
for (int i=nofd-1; i>=0; i--)
if (a[i]<ob.a[i])
return true;
else if(a[i]>ob.a[i])
return false;
return true;
}
}
class F009
{
public static void main(String args[])
{
hugeint a,b;
int choice;
a=new hugeint();
b=new hugeint();
do
{
a.inputhugeint();
b.inputhugeint();
String st="";
st+="Enter your choice from 1 to 9.\n";
st+="1. addhugeint.\n";
st+="2. subhugeint.\n";
st+="3. isEqualTo.\n";
st+="4. isNotEqualTo.\n";
st+="5. isGreaterThan.\n";
st+="6. isLessThan.\n";
st+="7. isGreaterThanOrEqualTo.\n";
st+="8. isLessThanOrEqualTo.\n";
st+="9. Exit.";

System.out.print("Select 1-9.");


String input=JOptionPane.showInputDialog(st);
choice=Integer.parseInt(input);

switch(choice)
{
case 1:
a.addhugeint(b);
a.outputhugeint();
break;

case 2:
a.subhugeint(b);
a.outputhugeint();
break;

case 3:
if (a.isEqualTo(b))
JOptionPane.showMessageDialog(null,"Equal.");
else
JOptionPane.showMessageDialog(null,"Not Equal.");
break;

case 4:
if (a.isNotEqualTo(b))
JOptionPane.showMessageDialog(null,"Not Equal.");
else
JOptionPane.showMessageDialog(null,"Equal.");
break;

case 5:
if (a.isGreaterThan(b))
JOptionPane.showMessageDialog(null,"Greater than.");
else
JOptionPane.showMessageDialog(null,"Not Greater than.");
break;

case 6:
if (a.isLessThan(b))
JOptionPane.showMessageDialog(null,"Less than.");
else
JOptionPane.showMessageDialog(null,"Not less than.");
break;

case 7:
if (a.isGreaterThanOrEqualTo(b))
JOptionPane.showMessageDialog(null,"Greater Than or equal to.");
else
JOptionPane.showMessageDialog(null,"Not Greater than or equal to.");
break;

case 8:
if (a.isLessThanOrEualTo(b))
JOptionPane.showMessageDialog(null,"Less than or equal to.");
else
JOptionPane.showMessageDialog(null,"Not less than or equal to.");
break;
}
}
while(choice!=9);
System.exit(0);
}
}