多组输入,一个整数(2~20),表示直角三角形直角边的长度,即“*”的数量,也表示输出行数。
针对每行输入,输出用“*”组成的对应长度的直角三角形,每个“*”后面有一个空格。
4
* * * * * * * * * *
5
* * * * * * * * * * * * * * *
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 a = in.nextInt(); for(int i=1;i<=a;i++){ for(int j=1;j<=i;j++){ System.out.print("*"+" "); } 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 n = sc.nextInt(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= i; j++) { System.out.print("* "); } 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 num = scanner.nextInt(); for(int i = 1;i <= num;i++){ for(int j = 1 ;j <= i;j++){ System.out.print("*" + " "); } System.out.println(""); } } } }
import java.util.*; public class Main{ public static void main(String love[]){ Scanner input=new Scanner(System.in); while(input.hasNextInt()){ int n=input.nextInt(); for(int i=0;i<n;i++){ for(int j=0;j<=i;j++){ System.out.print("*"+" "); } System.out.println(); } } input.close(); } }
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 j = 1; j <= n;j++){ for(int i = 1;i <= j;i++){ System.out.print("*"); System.out.print(" "); } 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()) { Integer number = sc.nextInt(); for(int j = 0 ; j <number ; j++) { for (int i = 0; i <=j; i++) { System.out.print("* "); } 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++) { System.out.println(String.join("", Collections.nCopies(i, "* "))); } } } }