nest 'for' loop.
/*
nest for loop demo.
Note that,'upside' triangle controls 'inner condition'.
*/
import kju.print.Print;
public class Pyramid {
public static void main(String[] args) {
upsideNumbers(5);
Print.println("------------------");
multiplicationTable(3);
Print.println("------------------");
pyramid(5);
}
/*shape begins:
----*
---* *
--* * *
-* * * *
shape ends:*/
static void pyramid(int height){
for(int i = 0; i < height; i++) { //all rows.
for(int j = i; j < height - 1; j++) //vitual for '-'.
Print.print(" ");
for(int j = 0; j <= i; j++)
Print.print("* ");
Print.println();
} //for(i)
} /*shape begins:
1
12
123
1234
12345
shape ends:*/
static void upsideNumbers(int height) {
for (int i = 1; i <= height; i++) {
for (int j = 1; j <= i ; j++)
Print.print(j);
Print.println();
}//for(i).
} /*shape begins:
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
shape ends:*/
static void multiplicationTable(int height){
for (int i = 1; i <= height; i++) {
for (int j = 1; j <= i; j++)
Print.print(j + "*" + i + "=" + (j * i) + "\t");
Print.println();
}//for(i)
}
}
nest 'for' loop.的更多相关文章
- 一种特殊场景下的HASH JOIN的优化为NEST LOOP.
应用场景: 有如下的SQL: select t.*, t1.ownerfrom t, t1where t.id=t1.id; 表t ,t1的数据量比较大,比如200W行.但是两张表能关联的行数却很少, ...
- The Node.js Event Loop, Timers, and process.nextTick() Node.js事件循环,定时器和process.nextTick()
个人翻译 原文:https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick/ The Node.js Event Loop, Ti ...
- Oracle 三种连接方式 NESTED LOOP HASH JOIN SORT MERGE JOIN
NESTED LOOP: 对于被连接的数据子集较小的情况,嵌套循环连接是个较好的选择.在嵌套循环中,内表被外表驱动,外表返回的每一行都要在内表中检索找到与它匹配的行,因此整个查询返回的结果集不能太大( ...
- oracle多表连接方式Hash Join Nested Loop Join Merge Join
在查看sql执行计划时,我们会发现表的连接方式有多种,本文对表的连接方式进行介绍以便更好看懂执行计划和理解sql执行原理. 一.连接方式: 嵌套循环(Nested Loops (NL) ...
- The Node.js Event Loop, Timers, and process.nextTick()
The Node.js Event Loop, Timers, and process.nextTick() | Node.js https://nodejs.org/uk/docs/guides/e ...
- Atitit 解决Unhandled event loop exception错误的办法
Atitit 解决Unhandled event loop exception错误的办法 查看workspace/.metadata/.log org.eclipse.swt.SWTError: No ...
- Looper.prepare()和Looper.loop()
什么时候需要 Looper Looper用于封装了android线程中的消息循环,默认情况下一个线程是不存在消息循环(message loop)的,需要调用Looper.prepare()来给线程创建 ...
- PostgreSQL-PL/pgSQL-cursor,loop
将spam_keyword表word字段的字符全部拆分,只是利用过程语言完成循环的操作而已. create or replace function proc1() returns setof text ...
- archlinux 加载loop模块,且设定loop设备个数
如果loop模块没有编译进内核就要先加载loop模块 modprobe loop 然后更改/etc/modprobe.d/modprobe.conf(有些文章写是在/etc/modprobe.conf ...
随机推荐
- 当用DJANGO的migrate不成功时。。。。
URL:http://my.oschina.net/u/862582/blog/355421 因为操作SQL数据库时不规范,或是多人开发时产生了同步问题,就可能导致正规的MIGRATE时不能完成. 已 ...
- 编写优质无错C程序秘诀!《经验谈》
这里我将陆续给大家载出我在以前学习和编写c代码时遇到的问题和解决方法.学习的心得,有些是经过查询一些曾经参加微软microsoft的开发小组的老程序员的书籍和资料后提供给大家! 首先,当发现错误时,要 ...
- OnScroll与OnTouchEvent方法的区别与联系
onScroll()方法和onTouchEvent()方法的执行过程应该是,先onTouchEvent()的ACTION_DOWN,然后是ACTION_MOVE和onScroll()方法同时进行,最后 ...
- EAFP和LBYL 两种防御性编程风格
EAFP:Easier to ask for forgiveness than permission 获得事后原理总是比事先得到许可要容易的多. 这个EAFP在python中表现的比较多.EAFP,T ...
- poj 2431 Expedition 贪心
简单的说说思路,如果一开始能够去到目的地那么当然不需要加油,否则肯定选择能够够着的油量最大的加油站加油,,不断重复这个贪心的策略即可. #include <iostream> #inclu ...
- css的定位机制
牛腩新闻发不系统中遇到了CSS(Cascading style sheets),第一次接触,比较陌生还!因为CSS很多关于元素定位的问题,并且很多情况下元素的位置以像素精度计.一个不小心就很头疼,为此 ...
- wpf 资源的重用
资源的利用 1) Window.Resource <Window.Resource> <ImageBrush x:Key="TitleBrush" TileMod ...
- jQuery EasyUI + struts2.3 + mongoDB 列表查询翻页JAVA样例
列表界面: 主要实现方式:前台组合json格式查询条件,提交至后台解析处理 一.前台搜索脚本 String.prototype.replaceAll = function (s1, s2) { ...
- linux远程管理工具
一.常见的远程管理控制方式主要有以下几种 ①RDP(remote desktop protocol)协议 远程桌面协议,我们常用的windows操作系统就是的远程桌面管理就是基于该协议的. ②teln ...
- 数据结构(并查集||树链剖分):HEOI 2016 tree
[注意事项] 为了体现增强版,题目限制和数据范围有所增强: 时间限制:1.5s 内存限制:128MB 对于15% 的数据,1<=N,Q<=1000. 对于35% 的数据,1<=N,Q ...