Program BigInt.java: ===================================================== class
ID: 441132 • Letter: P
Question
Program BigInt.java: ===================================================== class BigInt { private int digit[]; // represent the integer as an array of digits private int size; // number of digits in the integer private final int max = 50; // maximum number of digits in the integer public BigInt() { digit = new int[max]; for (int ct = 0; ct = 0; ct --) { digit[ct] = Integer.parseInt(num.substring(size - ct - 1, size - ct)); } } public BigInt(int num) { // constructor with initial integer value } public BigInt(BigInt num) { // copy constructor } public String toString() { // override ObjectExplanation / Answer
This is the code, It is working fine in eclipse . If you want any modification please let me know dont forget to rate ---------------------------------------------- package a; import java.util.Scanner; public class BigInt { static Scanner scan=new Scanner(System.in); private int digit[]; // represent the integer as an array of digits private static int size; // number of digits in the integer private final int max = 50; //maximum number of digits in the integer public BigInt(String num) { digit = new int[size]; int radix=size+1; for (int i=size-1,j=0; i>=0 ; i--,j++) { digit[j] = Character.digit(num.charAt(i),10); //System.out.println(digit[j]); } } public BigInt() { super(); } public String add(BigInt a,BigInt b) { String sum; int countLength; BigInt c=new BigInt(); int carry=0; c.digit=new int[size+1]; int j; for(j=0;j=10) { c.digit[j]=temp-10; carry=1; } else c.digit[j]=temp; } c.digit[j]=carry; System.out.print("The Sum is : "); for(int i=c.digit.length-1;i>=0;i--) System.out.print(c.digit[i]); return null; } public static void main(String[] args) { BigInt bigInt=new BigInt(); String num1,num2; System.out.println("Enter first BigInt "); num1=scan.nextLine(); System.out.println("Enter second BigInt"); num2=scan.nextLine(); if(num1.length()>=num2.length()) bigInt.size=num1.length(); else bigInt.size=num2.length(); BigInt a=new BigInt(num1); BigInt b=new BigInt(num2); String sum; sum=bigInt.add(a,b); } } ------------------------------------ sample output -------------------------- Enter first BigInt 123456789 Enter second BigInt 123456789 The Sum is : 0246913578
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.