#include<stdio.h> int main() { int j = 0, i = 0; for (j = 0; j < 6; j++) { for (i = 0; i < 12; i++) { if ((i == 5 || i == 6) && (j == 0 || j == 1)) { printf("*"); } else if (j == 2 || j == 3) { printf("*"); } else if ((j == 4 || j == 5) && (i == 4 || i == 7)) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }
#include<iostream> #include<vector> using namespace std; int main() { vector<string> str { " ** " ,"************" ," * * " }; for (int i = 0;i < 3;i++) { for (int j = 0; j < 2; j++) { cout << str[i] << endl; } } return 0; }c++的写法
#include <bits/stdc++.h> using namespace std; int main() { for(int i=0;i<11;i++){ if(i%2==0){ printf("\n"); } if(i==1||i==3){ printf(" **\n"); } if(i==5||i==7){ printf("************\n"); } if(i==9||i==11){ printf(" * *\n"); } } return 0; }为啥我这个不行啊,有没有大佬捞捞我
print(' '*5+'**'+' '*5) print(' '*5+'**'+' '*5) print('*'*12) print('*'*12) print(' '*4+'* *'+' '*4) print(' '*4+'* *'+' '*4) #加号拼接字符串
print('{:^12}'.format('**')) print('{:^12}'.format('**')) print('*'*12) print('*'*12) print('{:^12}'.format('* *')) print('{:^12}'.format('* *')) #format居中的格式化输出
public class Main { public static void main(String[] args) { for (int i = 0; i < 6; i++) { switch (i) { case 0: case 1: Main.setSpace(5); Main.setCross(2); System.out.println(""); break; case 2: case 3: Main.setCross(12); System.out.println(""); break; default: Main.setSpace(4); Main.setCross(1); Main.setSpace(2); Main.setCross(1); System.out.println(""); break; } } } public static void setSpace(int num) { for (int i = 0; i < num; i++) { System.out.print(" "); } } public static void setCross(int num) { for (int i = 0; i < num; i++) { System.out.print("*"); } } }
a = [] a.append("**") a.append("*"*12) a.append("* *") for i in a: print("{:^12}".format(i)) print("{:^12}".format(i))
print(' ** ') print(' ** ') print('************') print('************') print(' * * ') print(' * * ')