Java BigInteger

Sort by

recency

|

349 Discussions

|

  • + 0 comments

    Constraints a and b are non-negative integers and can have maximum 200 digits.

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        BigInteger x = BigInteger.valueOf(0);
        BigInteger a = new BigInteger(sc.next());
        BigInteger b = new BigInteger(sc.next());
    
        if(a.bitLength() < 200 && b.bitLength() < 200 && x.compareTo(a) < 0 && x.compareTo(b) < 0) 
            System.out.println(a.add(b));
            System.out.println(a.multiply(b));
    
    }
    

    }

  • + 0 comments

    public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ Scanner scan = new Scanner(System.in);

        String a = scan.next();
        String b = scan.next();
    
        BigInteger bia = new BigInteger(a);
        BigInteger bib = new BigInteger(b);
        BigInteger suma,multy;
    
        suma = bia.add(bib);
        multy = bia.multiply(bib);
    
        System.out.println(suma);
        System.out.println(multy);
    }
    
  • + 0 comments

    Consider this solution as reference,

        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            BigInteger first = new BigInteger(sc.next());
            BigInteger second = new BigInteger(sc.next());
            System.out.println(first.add(second));
            System.out.println(first.multiply(second));
       }
    
  • + 0 comments

    import java.io.; import java.util.; import java.util.Scanner; import java.math.BigInteger; public class Solution {

    public static void main(String[] args) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
            Scanner sc= new Scanner(System.in);
            BigInteger a = sc.nextBigInteger();
            BigInteger b = sc.nextBigInteger();
            BigInteger sum, mul;
            sum = a.add(b);
            mul = a.multiply(b);
            System.out.println(sum + "\n" + mul);
    }
    

    }****

  • + 0 comments
    
    

    import java.util.; import java.text.; import java.math.; import java.util.regex.;

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        BigInteger a = new BigInteger(sc.nextLine());
        BigInteger b = new BigInteger(sc.nextLine());
         BigInteger sum = a.add(b);
          BigInteger prod = a.multiply(b);
    
        System.out.println(sum+"\n"+prod);
    }
    

    }