多组输入,一个整数(3~20),表示数字三角形边的长度,即数字的数量,也表示输出行数。
针对每行输入,输出用数字组成的对应长度的数字三角形,每个数字后面有一个空格。
4
1 1 2 1 2 3 1 2 3 4
5
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()){ int n = in.nextInt(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } } in.close(); } }
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextInt()) { // 注意 while 处理多个 case int n = in.nextInt(); for(int i=1;i<=n;i++){ for(int j=1;j<=i;j++){ System.out.print(j+" "); } System.out.println(); } } } }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ int x=sc.nextInt(); for(int i=1;i<=x;i++){ for(int j=1;j<=i;j++) System.out.printf("%d ",j); System.out.println(); } } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNextInt()) { int n = sc.nextInt(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { System.out.print(j+" "); } System.out.println(); } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()){ int n = scanner.nextInt(); for(int i = 1;i <= n;i++){ for(int j = 1;j <= i;j++){ System.out.print(j + " "); } System.out.println(""); } } } }
import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); while(sc.hasNext()) { int a = sc.nextInt(); for(int i=1;i<=a;i++) { for(int j=1;j<=a;j++) { if(j<=i) { System.out.print(j+" "); } } System.out.println(); } } } }
import java.util.Scanner; /** * * @Title 数字三角形 * @Description KiKi学习了循环,BoBo老师给他出了一系列打印图案的练习,该任务是打印用数字组成的数字三角形图案。 * 输入描述: * 多组输入,一个整数(3~20),表示数字三角形边的长度,即数字的数量,也表示输出行数。 * 输出描述: * 针对每行输入,输出用数字组成的对应长度的数字三角形,每个数字后面有一个空格。 * @author weijunfu<ijunfu @ qq.com> * @date 2022/03/17 23:42 * @version 1.0.0 * */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNextInt()) { int num = in.nextInt(); for(int i=1; i<=num; i++) { for(int j=1; j<=i; j++) { System.out.print(j + " "); } System.out.println(); } } } }
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); for(int i = 1; i <= n ; i++){ for(int j = 1; j <= i; j++){ System.out.print(j + " "); } System.out.println(); } } } }
import java.util.*; public class Main{ public static void main (String[] args) { Scanner in = new Scanner(System.in); while (in.hasNext()) { int num = in.nextInt(); for (int i = 1; i <= num; i++) { for (int j = 1; j <= i; j++) { System.out.print(j + " "); } System.out.println(); } } } }