【基礎題】【for迴圈】二重迴圈
1.輸出以下格式
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
程式碼:
package com.itheima;
public class Main {
public static void main(String[] args) {
for(int i=1;i<10;i++){
for(int j=1;j<=i;j++){
System.out.print(j +" ");
}
System.out.println();
}
}
}
2.輸出以下格式
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
程式碼:
package com.itheima;
public class Main {
public static void main(String[] args) {
for(int i=1;i<10;i++){
for(int k=1;k<2*(10-i);k++){
System.out.print(" ");
}
for(int j=1;j<=i;j++){
System.out.print(j +" ");
}
System.out.println();
}
}
}
3.輸出以下格式
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
程式碼:
package com.itheima;
public class Main {
public static void main(String[] args) {
for(int i=1;i<10;i++){
for(int j=1;j<=10-i;j++){
System.out.print(j +" ");
}
System.out.println();
}
}
}
4.輸出以下格式
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
程式碼:
package com.itheima;
public class Main {
public static void main(String[] args) {
for(int i=1;i<10;i++){
for(int k=1;k<2*i;k++){
System.out.print(" ");
}
for(int j=1;j<=10-i;j++){
System.out.print(j +" ");
}
System.out.println();
}
}
}
5.列印三角形圖案
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
package com.itheima;
public class Main {
public static void main(String[] args) {
for(int i=0;i<5;i++){
for(int k=0;k<-2*i + 8;k++){
System.out.print(" ");
}
for(int j=0;j<(2*i+1);j++){
System.out.print("* ");
}
System.out.println();
}
}
}
相關文章
- python 基礎 迴圈Python
- JavaScript的map迴圈、forEach迴圈、filter迴圈、reduce迴圈、reduceRight迴圈JavaScriptFilter
- Python基礎(07):迴圈Python
- react基礎之-- 列表迴圈React
- 指令碼迴圈基礎(2)指令碼
- 12-JavaScript基礎-for迴圈JavaScript
- JAVA基礎--增強for迴圈Java
- C#程式設計基礎第七課:C#中的基本迴圈語句:while迴圈、do-while迴圈、for迴圈、foreach迴圈的使用C#程式設計While
- C語言——迴圈結構(for迴圈,while迴圈,do-while迴圈)C語言While
- 【Python基礎】for迴圈語句Python
- Python基礎教程06 - 迴圈Python
- 【基礎題】【for迴圈】分別輸出A~Z, a ~ z。
- Python基礎-While迴圈語句PythonWhile
- Python基礎學習之迴圈Python
- python基礎 while迴圈練習PythonWhile
- shell基礎教程 十六: Shell until迴圈
- Go 基礎知識之分支迴圈Go
- javascript基礎(控制流程(迴圈 while,for))(十二)JavaScriptWhile
- 04流程控制 for迴圈,while迴圈While
- Python基礎:條件判斷 & 迴圈Python
- 【重溫基礎】3.迴圈和迭代
- Python 快速教程(基礎篇06): 迴圈Python
- JS優化迴圈之展開迴圈JS優化
- require()迴圈引用問題UI
- JavaScript for of 迴圈JavaScript
- Java迴圈Java
- javascript迴圈JavaScript
- 事件迴圈事件
- while迴圈While
- javaScript for迴圈JavaScript
- scss中迴圈之@for迴圈佈局畫圓CSS
- matlab之在迴圈中修改迴圈變數Matlab變數
- java基礎(三) 加強型for迴圈與IteratorJava
- Java入門學習-學習if & else,for迴圈,foreach迴圈,while迴圈的用法。JavaWhile
- JS專題之事件迴圈JS事件
- Java無限迴圈問題Java
- PLSQL Language Referenc-PL/SQL控制語句-迴圈語句-FOR迴圈-FOR迴圈中的索引SQL索引
- 迴圈中的非同步&&迴圈中的閉包非同步