Java Job 6

Source: Internet
Author: User
Tags float double pow

1, using two-dimensional arrays and circular statements to make a Gobang disk

2. Write a program to convert integers to Kanji

3 Large Numbers

Four. Large number

4.

The previous introduction of the JDK provided by the BigInteger can complete the large number of calculations, if not use it, directly using the array to express large numbers, you can achieve the same function? Requirements: (1) Use your large number of classes to achieve plus and minus two functions (2) Read the BigInteger class source code, figuring out what algorithm is used to achieve subtraction four kinds of operations? (3) through the Internet to find the large number of relevant data, to your large number of classes to add multiply, divide, and other functions to seek factorial.

(1) BigInteger History Introduction
In Java, there are many kinds of data types, such as byte short char int float double long, and BigInteger belongs to one of the more special data types, which is also the focus of this tutorial. BigInteger already exists in the JDK1.1, belonging to the Java.math package class. By name, BigInteger represents a larger range of values than an integer. The basic structure of the BigInteger class is as follows:
Java.lang.Object
|_java.lang.number
|_java.math.biginteger
BigInteger implemented interfaces: Serializable, comparable<biginteger>

(2) BigInteger is an integer of immutable arbitrary precision. In all operations, BigInteger (such as the basic integer type of Java) are represented in twos complement form. BigInteger provides a counterpart to all Java's basic integer operators and provides all the relevant methods of Java.lang.Math. In addition, BigInteger provides the following operations: modulo arithmetic, GCD calculation, prime number test, prime generation, bit manipulation, and some other operations.

(3) BigInteger attribute Analysis
Here's a look at the key attributes of BigInteger, the main ones are the following three:
(1) Final int Signum
The Signum attribute is designed to differentiate between positive and negative and 0 flags, which are clearly stated in the JDK notes:
The signum of this BigInteger:-1 for negative, 0 for zero, or 1 for positive. Note that the BigInteger zero must has a signum of 0. This was necessary to ensures that there is exactly one representation for each BigInteger value.
(2) Final int[] Mag
Mag is an abbreviated form of magnitude, the mag array is stored BigInteger numeric size, in the order of Big-endian, that is, the high-level bytes into the low address, low-bit bytes into the high address, in order to arrange the way. The original JDK notes are as follows:
The magnitude of this BigInteger, in Big-endian order:the zeroth element of this array is the most-significant int of the Magnitude. The magnitude must is "minimal" in the and the Most-significant Int (mag[0]) must be non-zero. This was necessary to ensure that there is exactly one representation for each BigInteger value. Note that this implies, the BigInteger Zero has a zero-length mag array.
(3) Final static long long_mask = 0xffffffffL;
This mask was used to obtain the value of an int as if it were unsigned.

Package Work;import Java.util.scanner;public class Bignum {public    static void Main (string[] args) {        //TODO auto- Generated method stub            int aa,bb;      System.out.println ("Adding and subtracting large numbers with arrays");      System.out.print ("Please enter a large number A:");      Scanner scan=new Scanner (system.in);      String A=scan.next ();      System.out.print ("Please enter a large number B:");     String B=scan.next ();     int a[]=new int[100];     int b[]=new int[100];          for (int i=0;i<a.length (); i++) {         a[i]= (int) ((A.charat (i) -48) *math.pow (10,a.length ()-i-1));     }     for (int i=0;i<b.length (); i++) {         b[i]= (int) ((B.charat (i) -48) *math.pow (10,b.length ()-i-1));     }     int sum=0;     int sub=0;     for (int i=0;i<a.length (); i++) {         sum+=a[i]+b[i];         Sub+=a[i]-b[i];     }     System.out.print ("a+b=" +sum);      System.out.println ();      System.out.print ("a-b=" +sub);}    

Result Solution:

4 random number

The For loop generates 10 random numbers in the function, puts in the array, and puts the sum into the summation.

Java Job 6

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.