多组输入,一个整数(2~20)。
针对每行输入,输出用“*”组成的K形,每个“*”后面有一个空格。
2
* * * * * * * * * * *
3
* * * * * * * * * * * * * * * * * * *
4
* * * * * * * * * * * * * * * * * * * * * * * * * * * * *
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(); // 1 到 n + 1 for(int i = 1; i <= n + 1; i++) { for(int j = n + 1; j >= i; j--) { System.out.print("* "); } //换行 System.out.println(); } // n + 2 到 2 * n + 1 for(int i = 1; i <= n; i++) { for(int j = 1; j <= i + 1; j++) { System.out.print("* "); } //换行 System.out.println(); } } } }
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+1;i++){ for(int j=n+1;j>=i;j--){ System.out.print("* "); } System.out.println(); } for(int i=1;i<=n;i++){ for(int j=0;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 x=sc.nextInt(); for(int i=x+1;i>1;i--){ for(int j=1;j<=i;j++){ System.out.print("* "); } System.out.println(); } System.out.println("*"); for(int i=2;i<=x+1;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 c = 1; c <= n; c++) { for (int b = n - c + 2; b > 0; b--) { System.out.print("* "); } System.out.println(); } //中间线 System.out.println("* "); //下三角 for (int c = 1; c <= n; c++) { for (int b = 0 ; b < c + 1 ; b++) { 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 n = scanner.nextInt(); for(int i = 1 ; i <= n ;i++){ for(int j = i;j <= n + 1;j++){ System.out.print("* "); } System.out.println(""); } System.out.println("*"); for(int i = 1;i <= n;i++){ for(int j = 1;j <= i + 1;j++){ System.out.print("* "); } System.out.println(""); } } } }
import java.util.*; public class Main{ public static void main(String args[]){ Scanner input=new Scanner(System.in); while(input.hasNextInt()){ int n=input.nextInt(); for(int i=0;i<n+1;i++){ for(int j=n+1;j>i;j--){ System.out.print("* "); } System.out.println(); } for(int l=n;l>0;l--){ for(int k=0;k<=n+1-l;k++){ System.out.print("* "); } System.out.println(); } } input.close(); } }
import java.util.Scanner; /** * @Title: K形图案 * @Remark: KiKi学习了循环,BoBo老师给他出了一系列打印图案的练习,该任务是打印用“*”组成的K形图案。 * 输入描述: * 多组输入,一个整数(2~20)。 * * 输出描述: * 针对每行输入,输出用“*”组成的K形,每个“*”后面有一个空格。 * @Author: ijunfu * @Version: 1.0.0 * @Date: 2022-03-19 */ public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while(in.hasNextLine()) { Integer row = Integer.valueOf(in.nextLine()); for(int i=0; i<=row; i++) { for(int j=0; j<=row-i; j++) { System.out.print("* "); } System.out.println(); } for(int i=0; i<row; i++) { for(int j=0; j<=i+1; 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 n = scanner.nextInt(); for (int i = 0; i <= n; i++) { for (int j = 0; j <= n-i; j++) { System.out.print("* "); } System.out.println(); } for (int i = 0; i < n ; i++) { for (int j = 0; j <= i+1 ; j++) { 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++){ for(int j = 1; j <= n+2-i;j++){ System.out.print("* "); } System.out.println(); } System.out.println("*"); for(int i = 1; i <=n ;i++){ for(int j = 1; j <= i+1; 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()) { Integer number = sc.nextInt(); for(int n = number; n >= 0; n--){ for(int i = n; i >= 0; i--){ System.out.print("* "); } System.out.println(""); } for(int n = 1;n<=number;n++){ for(int j = n+1;j>0;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); int count; while(scanner.hasNext()) { count = scanner.nextInt(); for(int i=0;i<=count;i++) { for(int j=0;j<=count;j++) { if(j<=count-i) System.out.printf("* "); else System.out.printf(" "); } System.out.println(); } for(int i=0;i<count;i++) { for(int j=0;j<=count;j++) { if(j<=i+1) System.out.printf("* "); else System.out.printf(" "); } System.out.println(); } } } }
* * * * * * * * * * * * * * * * * * *
import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ int n = scanner.nextInt(); int m = n+1; List<String> list = new ArrayList<>(); for (int i = 1; i <= m ; i++) { String s = String.join("",Collections.nCopies(m+1-i, "* ")); //最后* 后面的空格 s += String.join("",Collections.nCopies(i-1," ")); list.add(s); } Boolean flag = true; for (int i = 0; i >= 0; ) { if(i == list.size()-1){ flag = false; } System.out.println(list.get(i)); i = flag ? ++i : --i; } } } }
import sys while True: try: num=int(sys.stdin.readline().strip())+1 for i in range(num*2-1): if i>num&nbs***bsp;i==num: print("* "*(i-num+2)+" "*(2*num-i-2)) else: #每一行宽度为N+1,不够的用空格填充 print("* "*(num-i)+" "*2*i) except: break
import java.util.Collections; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); while(input.hasNext()) { int n=input.nextInt(); for (int i = 0; i <= 2 * n; i++) { int filln = Math.abs(n - i) + 1; System.out.printf("%s\n", String.join("", Collections.nCopies(filln, "* "))); } } } }
import java.util.Scanner;
public class Test007{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int m=sc.nextInt()+1;
int j=m;
sc.close();
for (;j>0;j--){
for(int i=0;i<j;i++){
System.out.print("*"+" ");
} System.out.println();
}
for(int k=1;k<m;k++){
for(int i=0;i<=k;i++){
System.out.print("*"+" ");
} System.out.println();
}
}
}