zoukankan      html  css  js  c++  java
  • Java实验项目二——二维数组实现九九乘法表

    Program:打印乘法口诀表

        (1)编写一个方法,参数(二维数组),完成将二维数组中的数据按照行列显示的工作。

        (2)编写一个测试方法,给出99乘法表,放入到二维数组中,调用(1)中的方法,显示乘法口诀表。

    Description:main方法所在类在最后给出,代码如下:

     1 /*
     2  *Description:定义工具类,负责初始化二维数组和打印二维数组
     3  *
     4  * */
     5 
     6 package tools;
     7 
     8 
     9 public class Operate {
    10     
    11     //初始化二维数组
    12     public static String[][] init() {
    13         
    14         String[][] temp = new String[9][9];
    15         for( int i = 0; i < 9; i++ ) {
    16             
    17             for( int j = 0; j < 9; j++ ) {
    18                 if( j <= i ) {                //保存乘法表内容
    19                     temp[i][j] = (j + 1) + "*" + (i + 1) + "=" + ((i+1)*(j+1)) + "  ";
    20                 }
    21                 else {
    22                     temp[i][j] = "";        //不需要的地方赋值为:""
    23                 }
    24             }
    25             temp[i][i] += "
    ";                //加回车
    26         }
    27         
    28         return temp;            //返回二维数组
    29     }
    30     
    31     
    32     //打印数组元素
    33     public static void printInfo(String[][] temp) {
    34         
    35         for( int i = 0; i < temp.length; i++ ) {
    36             
    37             for( int j = 0; j < temp[i].length; j++ ) {
    38                 System.out.print( temp[i][j] );
    39             }
    40         }
    41     }
    42     
    43 }
     1 /*
     2  * Description:通过二维数组打印九九乘法表
     3  * 
     4  * Written By:Cai
     5  * 
     6  * Date Written;
     7  * 
     8  * */
     9 
    10 package main;
    11 
    12 import tools.Operate;
    13 
    14 public class DemoTwo2 {
    15 
    16     public static void main(String args[]) {
    17         
    18         String[][] temp = Operate.init();        //初始化二维数组
    19         Operate.printInfo(temp);                //打印数组
    20         
    21     }
    22 }
    初学小白,请多指教!
  • 相关阅读:
    logstash 字段引用
    Filter Conditions 过滤条件
    Not found org.springframework.http.converter.json.MappingJacksonHttpMessageConve
    rsyslog Properties
    rsyslog 模板
    rsyslog 基本结构
    awk RS ORS
    elasticsearch分布式特点
    spring事物配置,声明式事务管理和基于@Transactional注解的使用
    myBatis:事务管理
  • 原文地址:https://www.cnblogs.com/caizhen/p/7594356.html
Copyright © 2011-2022 走看看