多组输入,一个整数(2~20),表示翻转直角三角形直角边的长度,即“*”的数量,也表示输出行数。
针对每行输入,输出用“*”组成的对应长度的翻转直角三角形,每个“*”后面有一个空格。
5
* * * * * * * * * * * * * * *
6
* * * * * * * * * * * * * * * * * * * * *
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 = n; i > 0; i--) {
System.out.println(String.join("", Collections.nCopies(i, "* ")));
}
}
}
} import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
while(sc.hasNextInt()){
n = sc.nextInt();
for(int i = 0; i < n; i++){
for(int j =i ; j < n; j++){
System.out.print("* ");
}
System.out.println();
}
}
}}
#include<stdio.h>
int main()
{
int k = 0;
int i = 0;
int j = 0;
while (scanf("%d", &k) != EOF)
{
for (i = k; i > 0; i--) //生成 k 行
{
for (j = 0; j < i; j++) //生成每行的*
{
printf("* ");
}
printf("\n");
}
}
return 0;
} #include <stdio.h>
int main() {
int n, i, j;
while (scanf("%d", &n) != EOF) {
for (i = 1; i <= n; i++) {
for (j =1;j<=n-i+1; j++) {
printf("* ");
}
printf("\n");
}
}
return 0;
}