- /*输出菱形星形
- *
- * *
- * * *
- * * * *
- * * * * *
- * * * * * *
- * * * * * * *
- * * * * * *
- * * * * *
- * * * *
- * * *
- * *
- *
- */
- /*class LingXing {
- public static void main(String[] args) {
- for(int x=1;x<=13;x++){
- for(int m=0;m<=7-x;m++){
- System.out.print(" ");
- }
- if(x>7){
- for(int n=0;n<=x-7;n++){
- System.out.print(" ");
- }
- }
- for(int y=1;y<=x&&y<=14-x;y++){
- System.out.print("*"+" ");
- }
- System.out.println();
- }
- }
- }*/
- 键盘录入数据
- import java.util.Scanner;
- class LingXing {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入数据:");
- int a = sc.nextInt();
- if(a%2==0){
- for(int x=1;x<=a;x++){
- for(int m=0;m<=(a)/2-x;m++){
- System.out.print(" ");
- }
- if(x>(a)/2){
- for(int n=0;n<=x-((a)/2);n++){
- System.out.print(" ");
- }
- }
- for(int y=1;y<=x&&y<=(a)-x;y++){
- System.out.print("*"+" ");
- }
- System.out.println();
- }
- }else{
- for(int x=1;x<=a;x++){
- for(int m=0;m<=(a+1)/2-x;m++){
- System.out.print(" ");
- }
- if(x>(a+1)/2){
- for(int n=0;n<=x-((a+1)/2);n++){
- System.out.print(" ");
- }
- }
- for(int y=1;y<=x&&y<=(a+1)-x;y++){
- System.out.print("*"+" ");
- }
- System.out.println();
- }
- }
- }
- }
复制代码 |