这个实例主要考察对for循环语句的使用,出现递增规律的乘法表。

开发环境

     开发工具:Microsoft Visual Studio2010 旗舰版

具体步骤

     先是制作一个控制台项目,具体项目名称见下图:

     然后在Program.cs主函数中编写控制9*9乘法表,需要了解for循环语句的使用方法:

具体代码如下

   1:  using System;
   2:   
   3:  namespace NineToNineUnit
   4:  {
   5:      class Program
   6:      {
   7:          static void Main(string[] args)
   8:          {
   9:              string t = string.Empty;
  10:              for (int i = 1; i < 10; i++)
  11:              {
  12:                  for (int j = 1; j <=i; j++)
  13:                  {
  14:                      t = string.Format("{0}*{1}={2}  ", j, i,(j*i));
  15:                      if (j <= 10&&i<=10)
  16:                         Console.Write(t);
  17:                         
  18:                      if (i == j)
  19:                         Console.Write("\n");
  20:                  }
  21:                  Console.Write("\n");
  22:              }
  23:              Console.ReadKey();
  24:          }
  25:      }
  26:  }

运行效果图如下:

技术点

1、控制台语句使用,如Console.Ready()按任意键退出运行框,Console.Write()输出一行信息。

2、Format强制数据类型转换使用。

3、如上第一个for循环主要涉及9*9乘法表每一行信息的循环,第二个for循环主要涉及每一行里面信息的循环。

 

感想

通过for循环嵌套语句的使用,能够有序的显示9*9乘法表。希望通过小实例给大家带来一些启发,将该思想运用到实际项目中。

源码下载

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

for语句嵌套使用 实现9*9乘法表的更多相关文章

  1. while嵌套应用二:九九乘法表

    __author__ = 'zht' #!/usr/bin/env python # -*- coding: utf-8 -*- ''' #努力学习每一天 ''' #while嵌套应用二:九九乘法表 ...

  2. python(7)- 小程序练习:循环语句for,while实现99乘法表

    打印99乘法表 for 循环语句实现: for i in range(1,10): for j in range(1,10): print(j,"x",i,"=" ...

  3. JAVA之旅(二)——if,switch,for,while,do while,语句嵌套,流程控制break , continue ,函数,重载的示例总结

    JAVA之旅(二)--if,switch,for,while,do while,语句嵌套,流程控制break , continue ,函数,重载的示例总结 JAVA的思想真的很重要,所以要专心的学-- ...

  4. 99乘法表(for循环嵌套)

    计算乘法表 两个数相乘,外层循环代表被乘数,控制行数:内层代表乘数,控制列数. 循环嵌套,变量名不可以重复. 使用 break 语句让输出的乘法表更简洁. 使用 String 变量,做 String ...

  5. for语句应用:乘法表

    乘法表: for语句应用: 1: 2: public class chengfa { 3: public static void main(String[] args) { 4: //int i; 5 ...

  6. sql语句各种九九乘法表

    下面用while 和 if 条件写的SQL语句的四种九九乘法表 --9x9 左下角 ) BEGIN SET @S='' WHILE @J<=@I BEGIN )))))) END PRINT @ ...

  7. python的while嵌套 99乘法表 三角形和正方形

    python的99乘法表 num1=1 while num1<=9 : num2 = 1 while num2 <=num1 : print (str(num2)+"X" ...

  8. python利用for..in遍历,while循环嵌套编译九九乘法表的几种模式

    运用for....in...遍历的四种方向的九九乘法表: 左下角: import sysfor i in range(1,10): for j in range(1,i+1): sys.stdout. ...

  9. 使用whIle循环语句和变量打印九九乘法表

    -设置i变量declare @i int --设置j变量declare @j int --设置乘法表变量declare @chengfabiao varchar(1000)--给i,j,@chengf ...

随机推荐

  1. [JIT_APP]Activity生命周期相关的7个方法

    先发一张安卓官方文档里面的Activity生命周期图解 下面在对这7个生命周期内相关的方法做一些简单的介绍 OnCreate() 当Activity被创建的时候,会自动运行该方法.该方法做一些初始化动 ...

  2. 用PHP写的一个简单的分页类 1.0版

    <?php /* 分页类 用于实现对多条数据分页显示 version:1.0 author:Knight E-Mail:S.Knight.Work@gmail.com Date:2013-10- ...

  3. zabbix 飞信集成配置

    1.环境说明: (Gentoo Linux环境) # uname -a Linux Crob 2.6.34-gentoo #1 SMP Mon May 31 15:45:25 CST 2010 x86 ...

  4. python 2 处理HTTP 请求的包

    httplib httplib: https://docs.python.org/2/library/httplib.html python 的官方文档这样说明: This module define ...

  5. nopcommerce中文网

    nopcommerce中文网 | nopcommerce是国外asp.net领域一个高质量的b2c开源项目,基于EntityFramework和MVC开发,交流QQ群:75272942 nopcomm ...

  6. java小数点的两种处理方法

    1. java.text.DecimalFormat;        //此方法为四舍五入 例如:DecimalFormat df = new DecimalFormat("#.0" ...

  7. Pencil-一个开源免费的UI原型工具,自带ios和android模板

    Pencil是一个开源免费的UI原型工具,自带ios和android模板,可以很方便的做mockup. 下图是一个官方展示的模板:         

  8. 去除android ImageView “[Accessibility] Missing contentDescription attribute on image” warning

    1.在有警告的xml上选择Graphical Layout: 2.查看右上角的被涂鸦的地方,然后点击: 3.出现: 4.点击”Ignore Type“或者是“Disable Issue Type”(不 ...

  9. leetcode题解||Reverse Integer 问题

    problem: Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 ...

  10. 搜索框中“请输入搜索keyword”

    $(function(){    $("#ctl00_txtKey").val("请输入搜索keyword").addClass("search&qu ...