for语句嵌套使用 实现9*9乘法表
这个实例主要考察对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乘法表的更多相关文章
- while嵌套应用二:九九乘法表
__author__ = 'zht' #!/usr/bin/env python # -*- coding: utf-8 -*- ''' #努力学习每一天 ''' #while嵌套应用二:九九乘法表 ...
- python(7)- 小程序练习:循环语句for,while实现99乘法表
打印99乘法表 for 循环语句实现: for i in range(1,10): for j in range(1,10): print(j,"x",i,"=" ...
- JAVA之旅(二)——if,switch,for,while,do while,语句嵌套,流程控制break , continue ,函数,重载的示例总结
JAVA之旅(二)--if,switch,for,while,do while,语句嵌套,流程控制break , continue ,函数,重载的示例总结 JAVA的思想真的很重要,所以要专心的学-- ...
- 99乘法表(for循环嵌套)
计算乘法表 两个数相乘,外层循环代表被乘数,控制行数:内层代表乘数,控制列数. 循环嵌套,变量名不可以重复. 使用 break 语句让输出的乘法表更简洁. 使用 String 变量,做 String ...
- for语句应用:乘法表
乘法表: for语句应用: 1: 2: public class chengfa { 3: public static void main(String[] args) { 4: //int i; 5 ...
- sql语句各种九九乘法表
下面用while 和 if 条件写的SQL语句的四种九九乘法表 --9x9 左下角 ) BEGIN SET @S='' WHILE @J<=@I BEGIN )))))) END PRINT @ ...
- python的while嵌套 99乘法表 三角形和正方形
python的99乘法表 num1=1 while num1<=9 : num2 = 1 while num2 <=num1 : print (str(num2)+"X" ...
- python利用for..in遍历,while循环嵌套编译九九乘法表的几种模式
运用for....in...遍历的四种方向的九九乘法表: 左下角: import sysfor i in range(1,10): for j in range(1,i+1): sys.stdout. ...
- 使用whIle循环语句和变量打印九九乘法表
-设置i变量declare @i int --设置j变量declare @j int --设置乘法表变量declare @chengfabiao varchar(1000)--给i,j,@chengf ...
随机推荐
- Hdu 2475-Box LCT,动态树
Box Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- [ReadingNotes] Search the links, static final in the java
[ReadingNotes] Search the links, static final in the java */--> pre { background-color: #2f4f4f;l ...
- hdu 4717 The Moving Points(三分+计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4717 说明下为啥满足三分: 设y=f(x) (x>0)表示任意两个点的距离随时间x的增长,距离y ...
- 开源存储之ceph
小记,曾经的很多单骑,赵子龙,杨再兴,..............为大将者所应用的胆识和气度,值得敬仰! 名师出高徒啊, 周侗北宋末年之武术大师,相传为三国姜维的传人(真实性ruiy哥就不考察了哈), ...
- 第二十三章、软件安装: RPM, SRPM 与 YUM 功能
SRPM 的使用 : rpmbuild 包含Source code 的 SRPM 新版的 rpm 已经将 RPM 与 SRPM 的命令分开了,SRPM 使用的是 rpmbuild 这个命令,而不是 r ...
- (组合数学3.1.1.1)POJ 1146 ID Codes(字典序法)
/* * POJ_1146.cpp * * Created on: 2013年10月8日 * Author: Administrator */ #include <iostream> #i ...
- 使用Python扫描端口情况
#!/usr/bin/python# -*- coding:utf8 -*-# Python: 2.7.8# Platform: Windows# Authro: ...
- Qt on Android: Qt Quick 之 Hello World 图文具体解释
在上一篇文章,<Qt on Android:QML 语言基础>中,我们介绍了 QML 语言的语法,在最后我们遗留了一些问题没有展开,这篇呢,我们就正式開始撰写 Qt Quick 程序,而那 ...
- java中关于public class
在编写类的时候可以使用两种方式定义类: public class定义类: class定义类: 1,如果一个类声明的时候使用了public class进行了声明,则类名称必须与文件名称完 ...
- Map的迭代操作
Map的迭代操作 public static void main(String[] args) { Map<String, List<Integer>> map = new H ...