Classroom-driven brain

Source: Internet
Author: User
Tags mul

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

Source code: Package Array;import java.io.*;p ublic class qipan{//define a two-dimensional array to act as the chessboard private string[][] board;//define the size of the chessboard private static int board_size = 15;public void Initboard () {//Initialize checkerboard array BOARD = new string[board_size][board_size];//assigns each element as "╋", Used to draw the checkerboard for (int i = 0; i < board_size; i++) {for (int j = 0; J < Board_size; J + +) {Board[i][j] = "╋" in the Console;}} Method of output checkerboard on console public void Printboard () {//print each array element for (int i = 0; i < board_size; i++) {for (int j = 0; J < board_s IZE; J + +) {//print array elements without wrapping System.out.print (Board[i][j]);}    Outputs a newline character System.out.print ("\ n") after each line of array elements is printed;} public static void Main (string[] args) throws Exception {Qipan GB = new Qipan (); Gb.initboard (); Gb.printboard (); /This is the method used to get the keyboard input BufferedReader br = new BufferedReader (new InputStreamReader (system.in));                String inputstr = null; System.out.println ("Please enter the coordinates of your chess, should be in X, y format:");//br.readline (): Whenever you enter a line on the keyboard press ENTER, the content you just entered will be read by BR. while ((Inputstr = Br.readline ()) = null) {//the string entered by the user is delimited by a comma (,) as a delimiter, separated into 2 strings string[] Posstrarr = iNputstr.split (",");//convert 2 strings to the coordinates of the user playing chess int xPos = Integer.parseint (posstrarr[0]); int yPos = Integer.parseint (Posstrarr [1]); /assign the corresponding array element as "". GB.BOARD[XPOS-1][YPOS-1] = "";/* the computer randomly generates 2 integers, which are assigned to the board array as the coordinates of the computer chess. Also involved 1. The validity of the coordinates can only be a number, not beyond the Checkerboard Range 2. If the point of the chess, can not repeat chess. 3. After each chess game, you need to scan who won the */gb.printboard ();    System.out.println ("Please enter the coordinates of your chess should be in X, y format:");} }}

Board implementation approach: Use a two-dimensional array as a chessboard, with "+" to initialize the board. Defines two methods one to define the chessboard and the other to output the chessboard on the console.

Write a program to convert an integer to a kanji read string.

Program run:

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

Source code: Package ketanglizishuzu;/* * Digital expression converted to man expression * Du Zekun * 2016/11/5 */import java.util.scanner;public class Dashupointer {p        Ublic static void Main (string[] args) {System.out.println ("Please enter the number to be converted");        Scanner str=new Scanner (system.in);        String S=str.next ();               Char A[]=s.tochararray ();       Convert this string number to a character array to store up string c[]={"points", "angle", "" "," Yuan "," Pick "," Bai "," Thousand "," Million "}; Create an array of type string to hold the unit for (int i=0;i<s.length (); i++)//To convert the number to the kanji {if (a[i]== ' 1 ') a[i            ]= ' one ';            if (a[i]== ' 2 ') a[i]= ' II ';            if (a[i]== ' 3 ') a[i]= ' three ';            if (a[i]== ' 4 ') a[i]= ' premises ';            if (a[i]== ' 5 ') a[i]= ' ng ';            if (a[i]== ' 6 ') a[i]= ' land ';            if (a[i]== ' 7 ') a[i]= ' qi ';            if (a[i]== ' 8 ') a[i]= ' BA ';            if (a[i]== ' 9 ') a[i]= ' JIU ';                    if (a[i]== '. ') a[i]= '; } for (int i=0;i<s.length (); i++) {System.out.print (A[i]+c[s.length ()-i-1])                ;    }    }} 

Results:

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) Add and subtract two functions with your large number of classes

(2) Read the BigInteger class source code, figuring out what algorithm it uses 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.

Package Ketanglizishuzu;import Java.math.biginteger;public class Dashuzhuan {public static void main (string[] args) {
   biginteger a =new BigInteger ("ten");   BigInteger b= New BigInteger ("a");   BigInteger Sub=a.subtract (b);//BigInteger of large integers   add=a.add (b);//large integers plus   BigInteger mul=a.multiply (b);//multiplication of large integers   BigInteger Div=a.divide (b);//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 ());}}

Results:

Randomly generates 10 numbers, fills an array, then displays the array contents with a message box, computes the array element's and displays the result in a message box.

Package ketanglizishuzu;/* * Random number * Du Zekun */import javax.swing.*;p ublic class Random {public static void main (String args[]) {    int a[]=new int [ten];    int sum=0;    Random rand=new random ();    String output= "";    for (int i=0;i<10;i++) {       a[i]= (int) (Math.random () *100);       Output+=string.valueof (A[i]) + "";    }    Joptionpane.showmessagedialog (null, Output,            "Initializing an Array with a Declaration",            Joptionpane.information_message);            Joptionpane.showmessagedialog (Null,sum, "the and of all elements in the array:",            joptionpane.information_message);}   }

Classroom-driven 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.