使用for循环嵌套实现乘法口诀表
九九乘法表的实现:
package com.liaojianya.chapter1;
/**
* This program demonstrates the way of using
* for-loop to implement the multiplication tables.
* @author LIAO JIANYA
* 2016年7月19日
*/
public class ForDemo
{
public static void main(String[] args)
{
for(int i = 1; i < 10; i++)
{
for(int j = 1; j <= i; j++)
{
System.out.print(i + "*" + j + "=" + (i * j) + "\t");
}
System.out.println();
}
} }
运行结果:
1*1=1
2*1=2 2*2=4
3*1=3 3*2=6 3*3=9
4*1=4 4*2=8 4*3=12 4*4=16
5*1=5 5*2=10 5*3=15 5*4=20 5*5=25
6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36
7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49
8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64
9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81
分析:整个程序执行1+2+3+...+9 = 45次循环
使用for循环嵌套实现乘法口诀表的更多相关文章
- .Net基础篇_学习笔记_第六天_for循环的嵌套_乘法口诀表
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 用一个for循环实现打印乘法口诀表
本博客不再更新,很多其它精彩内容请訪问我的独立博客 循环体内定义两个变量.一个控制列,一个控制行. for(int i=0,j=0;j<9;i++){ System.out.println(j+ ...
- C 语言实例 - 输出九九乘法口诀表
C 语言实例 - 输出九九乘法口诀表 使用嵌套 for 循环输出九九乘法口诀表. 实例 #include<stdio.h> int main(){ //外层循环变量,控制行 ; //内层循 ...
- java输出九九乘法口诀表
使用双重for循环输出九九乘法口诀表 public static void main(String[] args){ formula();} /** * for 循环实现9*9乘法口诀表 * &quo ...
- js用for循环实现乘法口诀表
for循环可以打印一个乘法口诀表.需要使用for循环的嵌套 <script> for(var i = 0; i <= 9; i++){ // 外层循环控制行数,外层循环执行一次,内层 ...
- for 循环 乘法口诀表
用for循环写乘法口诀表: for(var i = 1; i <= 9; i++) { var c=''; for(var x = 1; x <= i; x++) { c=c+x+' ...
- 用列表+for循环生成乘法口诀表
1 # 结合一下列表生成, 准备设计乘法表 2 # numlist = [1,2,3,4,5] 3 # [pow(i,3) for i in numlist] 4 # ## [1, 8, 27, 64 ...
- 使用 JavaScript 用循环嵌套输出乘法表。外循环控制行数,内循环控制当前行要输出的乘法表达式,在页面上输出九九乘法表
查看本章节 查看作业目录 需求说明: 在页面上输出九九乘法表,实现效果如图所示 实现思路: 创建HTML页面 在页面中嵌入 <script type="text/javascript& ...
- 用SQL打印乘法口诀表
--用SQL打印出乘法口诀表 declare @i int ,@j int --@i是乘法口诀的行数 --一共九行 begin --每次都是从1*开始,j每循环一次递增 )--print每次输出都会换 ...
随机推荐
- AKKA初体验
关于thread和actor下面这段话讲的很好Experienced developers have learned to be very careful with unrestricted thre ...
- forward和redirect 的区别
一.使用区别 1.从地址栏显示来说 forward是服务器请求资源,服务器直接访问目标地址的URL,把那个URL的响应内容读取过来,然后把这些内容再发给浏览器.浏览器根本不知道服务器发送的内容从哪里来 ...
- 转载:monkeyrunner工具
前言: 最近开始研究Android自动化测试方法,对其中的一些工具.方法和框架做了一些简单的整理,其中包括 android测试框架.CTS.Monkey.Monkeyrunner.benchmark. ...
- 报错:Cannot insert explicit value for identity column in table 't' when identity_insert is set to OFF
通常情况下,不能向 SQL Server 自增字段插入值,如果非要这么干的话,SQL Server 就会好不客气地给你个错误警告: Server: Msg 544, Level 16, State 1 ...
- hdoj 1068 Girls and Boys【匈牙利算法+最大独立集】
Girls and Boys Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 关于升级linux下apache
1:Check whether Apache is already installed. # rpm -qa | grep -i http httpd-tools-2.2.8-3.i386 httpd ...
- opencv学习笔记-图像对比度、亮度调节
在数学中我们学过线性理论,在图像亮度和对比度调节中同样适用,看下面这个公式: 在图像像素中其中: 参数f(x)表示源图像像素. 参数g(x) 表示输出图像像素. 参数a(需要满足a>0)被称为增 ...
- eclipse+tomcat+httpServlet初学
1.在eclipse中配置tomcat,参考上一边文章,建立的web项目tomcatWeb目录结构 2.添加Servlet处理类 3. 实现doGet()与doPost()方法: <span s ...
- SOA体系结构基础培训教程-规范标准篇
引子:本文是<SOA体系结构基础培训教程>第3章<SOA标准与规范>课件,版权所有,转载请注明出处. 随着SOA在业界的应用日益广泛,SOA的标准化问题也成为各界日益关注的焦点 ...
- cocos2d-x 事件分发机制 ——加速计事件监听
加速计事件监听机制 在上一篇中介绍了cocos2d-x中的触摸事件机制,这篇来介绍下游戏中也常常常使用到的加速计事件,这些都是游戏中的常常要用到的. 移动设备上一个非常重要的输入源是设备的方向.大多数 ...