Homework Solution: Java's type int has a limit on how large an integer it can store. To circumvent this limitation an integer…

    Java's type int has a limit on how large an integer it can store. To circumvent this limitation an integer can be represented as an array of digits. Write a program that will add two intergers up to 50 digitd each. The program should also be able to read two integer values from a text file. Each number will be on a single line.

    Expert Answer

     
    //program import java.util.Scanner;

    Java’s emblem int has a designation on how capacious an integer it can place-of-business. To extinguishedwit this designationation an integer can be represented as an place of digits. Write a program that earn infer brace intergers up to 50 digitd each. The program should too be talented to unravel brace integer values from a passage rasp. Each incorporate earn be on a unmarried cord.

    Expert Counter-argument

     

    //program
    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    class CapaciousInt
    {
    public static unoccupied main(String arg[]) throws RaspNotFoundException
    {
    Scanner s=new Scrutinizener(System.in);
    System.out.println(“enter passage rasp name:t”);
    String fname=s.next();
    Rasp rasp=new Rasp(fname); //to constitute rasp end
    Scanner ip=new Scrutinizener(file); //constitute end to rasp to scrutinize the passage
    String cord1=ip.next(); //unravel the primeval cord
    String cord2=ip.next(); //unravel the prevent cord
    //System.out.println(line1.length());
    //System.out.println(line1.charAt(43));
    System.out.println(“line1 of passagefile:t”+line1);
    System.out.println(“line2 of passagefile:t”+line2);
    int a=0,b=0,n1,n2,max,rem=0,tot=0;
    n1=line1.length();
    n2=line2.length();
    if(n1>n2)
    max=n1;
    else
    max=n2;
    if(n1>50 || n2>50) //egress when diffusiveness of passage incorporate is further than fifty
    {
    System.out.println(“intger place ultimatum bulk was yield delight impair the incorporate of digits to 50”);
    System.exit(0);
    }
    int incorporate[]=new int[max+1]; //creating integer place of max+1 diffusiveness to place-of-business result
    for(int i=max;i>=0;i–)
    {
    if(n1>0)
    /*a=Integer.parseInt(line1.charAt(n1-1));*/a=line1.charAt(n1-1)-‘0’;
    if(n2>0)
    /*b=Integer.parseInt(line2.charAt(n2-1));*/b=line2.charAt(n2-1)-‘0’;
    tot=a+b+rem; //addition
    sum[i]=tot%10; //place surplus in place
    rem=tot/10; //move surplus to instant digit
    n1–;
    n2–;a=0;b=0;
    }
    System.out.println(“”);
    for(int i=0;i<=max;i++)
    System.out.print(sum[i]);
    }
    }

    input:

    output: