The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Please help me to fix these errors  i am getting three errors please fix ASAP
Â
Main.java:86: error: cannot find symbol
int t = (a[j] * b[i]) + c[i+j] + carry;
^
symbol: variable a
location: class BigInt
Main.java:86: error: cannot find symbol
int t = (a[j] * b[i]) + c[i+j] + carry;
^
symbol: variable b
location: class BigInt
Main.java:86: error: cannot find symbol
int t = (a[j] * b[i]) + c[i+j] + carry;
^
symbol: variable c
location: class BigInt
3 errors
Â
Â
public class Main {
public static void main(String[] args)
{
BigInt a = new BigInt("99");
BigInt b = new BigInt("9");
System.out.println(a + " + " + b + " = " + a.add(b));
System.out.println(a + " - " + b + " = " + a.sub(b));
System.out.println(a + " * " + b + " = " + a.mul(b));
}
}
class BigInt
{
public BigInt()
{
num = new int[1];
}
public BigInt(String s)
{
num = new int[s.length()];
for (int i = 0; i {
num[num.length - i - 1] = s.charAt(i) - '0';
}
num = trim(num);
}
private BigInt(int[] n)
{
this.num = new int[n.length];
for (int i = 0; i {
this.num[i] = n[i];
}
}
public BigInt add(BigInt o)
{
int carry = 0;
int max = num.length > o.num.length ? num.length : o.num.length;
int[] result = new int[max+1];
for (int i = 0; i {
int top = i int bot = i result[i] = (top + bot + carry) % 10;
carry = (top + bot + carry) / 10;
}
return new BigInt(trim(result));
}
public BigInt sub(BigInt o)
{
int borrow =10;
int max = num.length > o.num.length ? num.length : o.num.length;
int[] result = new int[max];
int x = 0;
for (int i = 0; i {
int top = i int bot = i if (top if(x > 0)
{
result[i] = ((((top - x)+borrow))-bot);
x = 0;
x += 1;
}
else
{
result[i]= (top - bot) + borrow;
num[i+1] -= 1;
}
if( top == bot || top > bot)
result[i] = (top - bot) % 10;
}
return new BigInt(trim(result));
}
Â
public BigInt mul(BigInt o)
{
int max = num.length > o.num.length ? num.length : o.num.length;
int[] result = new int[max];
for(int i=0;i {
int carry = 0;
for(int j=0;j {
int t = (a[j] * b[i]) + c[i+j] + carry;
carry = t/10;
result[i+j] = t%10;
}
}
return new BigInt(trim(result));
}
public String toString()
{
String s = "";
for (int i : num)
{
s = i + s;
}
return s;
}
private int[] trim(int[] nums)
{
int size = nums.length;
Â
for (int i = nums.length - 1; i > 0; --i)
{
if (nums[i] != 0)
{
break;
}
--size;
}
int[] res = new int[size];
for (int i = 0; i {
res[i] = nums[i];
}
return res;
}
private int[] num;
}
-----------