The large number class in Java is simply implemented

  • 2020-06-15 08:54:54
  • OfStack

The large number class in Java is simply implemented

The large Numbers in Java are still useful and convenient, so they are listed below for use


  import java.math.*; 
  import java.util.*; 
 
// Basic usage is as follows:  
            x = in.nextBigInteger(); 
    y = in.nextBigInteger(); 
 
            System.out.println(x.add(y)); //x+y; 
    System.out.println(x.subtract(y)); //x-y; 
    System.out.println(x.multiply(y)); // x*y; 
    System.out.println(x.remainder(y)); // x%y; 
 
            System.out.println(x.abs()); // x Absolute value of;  
    System.out.println(x.compareTo(y)==0); //x and y To compare the    
     
    System.out.println(x.toString(2)); //  into  x  the  n Into the system ; 
 
            x=BigInteger.ONE; // right x For the assignment  
    x=BigInteger.valueOf(5);//  right x To do the assignment, using the long/int  Type data  
 
            System.out.println(x); 

Thank you for reading, I hope to help you, thank you for your support to this site!


Related articles: