06 of the hands-on brain in Java

Source: Internet
Author: User

Task One:

Code:

Package Shi;

Import Javax.swing.JOptionPane;

public class Shi6d1 {

public static void Main (string[] args) {

int array[] = new INT[10];

for (int m=0;m<10;m++)

{Array[m] = (int) (Math.random () *100);}

String str= "";

for (int m=0;m<10;m++)

{str=str+array[m]+ "";}

int b=0;

for (int m=0;m<10;m++)

{b=b+array[m];}

Str=str+ " and as:" +B;

Joptionpane.showmessagedialog (Null,str, "", joptionpane.plain_message);

}

}

Ideas:

Define an array with a length of ten, then Assign the values randomly by the For loop, then define an int type variable b in the array Ten and then assigns each number in the array plus a space to a String type of Str , at the end plus and then output through the dialog box.

Program Flowchart:

Hands-on brain:

Board:

Code:

P ackage Shi;

Import java.io.*;

public class Qipan

{

define a two-dimensional array to act as a chessboard

Private string[][] board;

define the size of the board

private static int board_size = 15;

public void Initboard ()

{

initializing an array of checkers

board = new String[board_size][board_size];

assign each element "╋"todraw a chessboard on the console

for (int i = 0; i < board_size; i++)

{

for (int j = 0; J < Board_size; J + +)

{

BOARD[I][J] = "╋";

}

}

}

How to output a checkerboard in the console

public void Printboard ()

{

Print each array element

for (int i = 0; i < board_size; i++)

{

for (int j = 0; J < Board_size; J + +)

{

print array elements without wrapping

System.out.print (Board[i][j]);

}

outputs a newline character after each line of array elements is printed

System.out.print ("\ n");

}

}

public static void Main (string[] args) throws Exception

{

Qipan GB = new Qipan ();

Gb.initboard ();

Gb.printboard ();

This is the method for getting 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)

{

Separates the user-entered stringinto 2 strings with a comma (,) as a delimiter

string[] Posstrarr = Inputstr.split (",");

converts 2 strings to the coordinates of a user's 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 a computer's chess game .

also involves

1. the validity of the coordinates, can only be a number, not beyond the board range

2. if the point of chess under, can not repeat chess.

3. after each play, you need to scan who wins .

*/

Gb.printboard ();

System.out.println (" Please enter the coordinates of your chess, should be in x, y format:");

}

}

}

Digital conversion Capitalization:

Code:

Package Shi;

Import Javax.swing.JOptionPane;

public class Shi6d2 {

public static void Main (string[] args) {

String as=joptionpane.showinputdialog (" input number ");

Double number=double.parsedouble (AS);

number=number*100;

int n=0,num= (int) number; discard all after parting

int array[]=new int[9];

for (int i=0;i<10;i++) {

if (num==0)

Break

array[i]=num%10;

NUM=NUM/10;

n++;

}

String str[]={" minute ", " angle ", " meta ", " pick ", " Bai "," thousand "," million "," 10 "," Bai "};

String str1[]={" 0 ", " one "," II ", " three ", " Wu Lu Qi BA JIU

for (int i=n-1;i>=0;i--) {

System.out.print (Str1[array[i]);

System.out.print (Str[i]); }}}

:

Large number:

Code:

Addition

I mport javax.swing.*;

P ublic class Big {

P ublic static void main (string[] args) {

String num1=joptionpane.showinputdialog (" First number ");

String num2=joptionpane.showinputdialog (" first number ");

I NT nu1[]=new int[10];

I NT nu2[]=new int[10];

I NT nu3[]=new int[10];

I NT j=0;

for (int i=num1.length () -1;i>=0;i--) {

Nu1[j++]=num1.charat (i)-' 0 ';

}

j=0;

for (int i=num2.length () -1;i>=0;i--) {

Nu2[j++]=num2.charat (i)-' 0 ';

}

I NT next=0;

for (int i=0;i<nu1.length;i++) {

nu3[i]= (Nu1[i]+nu2[i]+next)%10;

next= (Nu1[i]+nu2[i]+next)/10;

}

for (int i=nu3.length-1;i>=0;i--) {

System.out.print (Nu3[i]);

}

}

}

Subtraction

P ackage Array;

Import javax.swing.*;

P ublic class Big {

P ublic static void main (string[] args) {

String num1=joptionpane.showinputdialog (" first number ");

String num2=joptionpane.showinputdialog (" first number ");

I NT nu1[]=new int[10];

I NT nu2[]=new int[10];

I NT nu3[]=new int[10];

I NT j=0;

for (int i=num1.length () -1;i>=0;i--) {

Nu1[j++]=num1.charat (i)-' 0 ';

}

j=0;

for (int i=num2.length () -1;i>=0;i--) {

Nu2[j++]=num2.charat (i)-' 0 ';

}

// Two number comparison size

I NT flag=0;

for (int i=nu1.length-1;i>=0;i--) {

if (Nu1[i]>nu2[i]) {

FLAG=1;BREAK;//1 represents 1 Digital Big

}

if (Nu1[i]<nu2[i]) {

FLAG=2;BREAK;//2 represents 2 Digital Big

}

}

I NT next=0;

if (flag==1) {

for (int i=0;i<nu1.length;i++) {

Nu3[i]=nu1[i]-nu2[i]+next;

if (nu3[i]<0) {

Next=-1;

nu3[i]=nu3[i]+10;

}

Else

next=0;

}

for (int i=nu3.length-1;i>=0;i--) {

System.out.print (Nu3[i]);

}}

if (flag==2) {

for (int i=0;i<nu1.length;i++) {

Nu3[i]=nu2[i]-nu1[i]+next;

if (nu3[i]<0) {

Next=-1;

nu3[i]=nu3[i]+10;

}

Else

next=0;

}

System.out.print ("-");

for (int i=nu3.length-1;i>=0;i--) {

System.out.print (Nu3[i]);

}

if (flag==0) {

System.out.println ("0");

}}

}

}

06 of the hands-on brain in Java

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.