"Java" Array and after-class hands-on brain

Source: Internet
Author: User
Tags float double mul

1. Read the Qipan.java sample program to learn how to draw a Gobang disk using two-dimensional arrays and circular statements.

Results and:

2. Write a program to convert an integer to a kanji reading string. For example, "1123" is converted to "1123".

Results:

3. Further, can the amount represented in the figure be changed to "Chinese character expression?" For example, the "¥123.52" converted to "one Bai San Yuan Wu angle of the three points."

Results:

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.

Import Java.math.BigInteger;

public class Text {

public static void Main (string[] args) {

TODO auto-generated Method Stub

BigInteger AA =new BigInteger ("100");

BigInteger bb= New BigInteger ("25");

BigInteger sub=aa.subtract (BB);///large integer minus

BigInteger Add=aa.add (BB);//The addition of large integers

BigInteger mul=aa.multiply (BB);//multiplication of large integers

BigInteger div=aa.divide (BB);//The addition of large integers

System.out.println ("Minus of large integers:" +sub.tostring ());

System.out.println ("Plus of large integers:" +add.tostring ());

System.out.println ("Multiplication of large integers:" +mul.tostring ());

SYSTEM.OUT.PRINTLN ("Except for large integers:" +div.tostring ());

}

}

Subtraction of large integers: 75

Addition of large integers: 125

Multiplication of large integers: 2500

Except for large integers: 4

5. Randomly generate 10 numbers, populate an array, then display the contents of the array with a message box, then calculate the array elements and display the results in a message box.

1. Design Ideas

Randomly generates 10 numbers, fills an array, computes the array elements with a for loop, and displays the array contents and calculation results with a message box.

2. Program Flowchart

3. Source code

4. Results

"Java" Array and after-class hands-on brain

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.