Home > Java > javaTutorial > body text

Simple code implementation of large number class in Java

黄舟
Release: 2017-03-28 10:26:39
Original
1129 people have browsed it

This article mainly introduces relevant information about the simple implementation of large number classes in Java. Friends in need can refer to

Simple implementation of large number classes in Java

Large numbers in Java are quite easy to use and very convenient, so they are listed below for ready use

  import java.math.*; 
  import java.util.*; 
 
//基本使用如下: 
            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的绝对值; 
    System.out.println(x.compareTo(y)==0); //x和y进行比较   
     
    System.out.println(x.toString(2)); // 转化为 x 的 n进制; 
 
            x=BigInteger.ONE; //对x进行赋值 
    x=BigInteger.valueOf(5);// 对x进行赋值,使用的是long/int 类型数据 
 
            System.out.println(x);
Copy after login

The above is the detailed content of Simple code implementation of large number class in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!