Java Experimental Project Two--two-dimensional array implementation 99 multiplication table

Source: Internet
Author: User

Program: Print multiplication tables

(1) Write a method, a parameter (a two-dimensional array), to complete the work of displaying the data in a two-dimensional array in rows and columns.

(2) Write a test method, give 99 multiplication table, put into a two-dimensional array, call the method in (1), display the multiplication table.

The class of the Description:main method is given at the end, and the code is as follows:

1 /*2 *description: Defines a tool class, responsible for initializing two-dimensional arrays and printing two-dimensional arrays3  *4  * */5 6  Packagetools;7 8 9  Public classOperate {Ten      One     //initialize a two-dimensional array A      Public Staticstring[][] Init () { -          -string[][] Temp =NewString[9][9]; the          for(inti = 0; I < 9; i++ ) { -              -              for(intj = 0; J < 9; J + + ) { -                 if(J <= i) {//Save multiplication Table contents +TEMP[I][J] = (j + 1) + "*" + (i + 1) + "=" + ((i+1) * (j+1)) + ""; -                 } +                 Else { ATEMP[I][J] = "";//where you don't need to assign a value of: "" at                 } -             } -Temp[i][i] + = "\ n";//Add carriage return -         } -          -         returnTemp//returns a two-dimensional array in     } -      to      +     //Print array elements -      Public Static voidprintinfo (string[][] temp) { the          *          for(inti = 0; i < temp.length; i++ ) { $             Panax Notoginseng              for(intj = 0; J < Temp[i].length; J + + ) { - System.out.print (Temp[i][j]); the             } +         } A     } the      +}

1 /*2 * Description: 99 multiplication Table printed with two-dimensional array3  * 4 * Written By:cai5  * 6 * Date written;7  * 8  * */9 Ten  Packagemain; One  A Importtools. Operate; -  -  Public classDEMOTWO2 { the  -      Public Static voidMain (String args[]) { -          -string[][] temp = Operate.init ();//initialize a two-dimensional array +Operate.printinfo (temp);//Print Array -          +     } A}

Java Experimental Project Two--two-dimensional array implementation 99 multiplication table

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.