Java--学习九九乘法表
2013-12-28 18:34
239 查看
class For{ public static void main(String[] args){ /* ***** **** *** ** * */ //错误代码: int z=5; for(int x=0;x<5;x++)//外部for循环决定行数,内部for循环决定列数。 { for(int y=0;y<z;y++) { System.out.print ("*"); z--; } System.out.println (); } System.out.println("-----------------"); /* 错误!! 结果为: *** * * (空格) (空格) 流程:第一次循环,输出*** 第二次循环,z=2,输出* 第三次循环,z=1,输出* 第四、五次循环,z=0,均输出 换行 */ //正确代码_1 int z=5; for(int x=0;x<5;x++) { for(int y=0;y<z;y++) { System.out.print ("*"); } System.out.println (); z--; } System.out.println("-----------------"); //正确代码_2 int z=0; //int z=0;(省略) for(int x=0;x<5;x++) { for(int y=z;y<5;y++) //for(int y=x;y<5;y++)因为z=0,x=0;z=1,x=1; { System.out.print("*"); } System.out.println(); z++; //z++(省略) } /* * ** *** **** ***** */ for(int x=0;x<5;x++) { for(int y=0;y<=x;y++) { System.out.print ("*"); } System.out.println (); } System.out.println("-----------------"); //尖朝上记住改变条件即可。如果y<x,就是0<0,结果第一行是换行。所以,应该是y<=x就靠谱了. //九九乘法表 for(int x=1;x<=9;x++) { for(int y=1;y<=x;y++) { System.out.print (y+"*"+x+"="+y*x+"\t"); } System.out.println (); } System.out.println("-----------------"); } } 会编译出错,因为多次定义了z,但内部的程序都是正确的……
相关文章推荐
- [java学习]九九乘法表
- 【Java学习笔记】使用for循环编写九九乘法表
- Java学习-----各种样式的九九乘法表
- java学习之旅22--综合练习_九九乘法表
- JAVA学习笔记_输出九九乘法表
- Java学习:打印金字塔和九九乘法表
- 我的java学习路之循环学习应用demo1九九乘法表
- 简单学习二维码生成步骤--java代码实现
- 学习记录——【转】java中打开explorer
- Java 线程池学习
- java系统学习(六) --------继承
- Java并发框架Executor学习(1)——简介
- java例题学习:猜数字游戏
- Java学习【知识点1】
- Java学习过程中要记录的地方--汇总
- JAVA程序性能优化-让你的java程序更快、更稳定学习笔记一性能优化一般步骤
- Java学习日记13——File*putStream的方法
- java学习--IO流(3)-Properties
- Java学习笔记14
- 黑马程序员--java学习笔记第七天