java吧 关注:1,243,622贴子:12,719,150
  • 16回复贴,共1
新人求教 如何用java 画出这样的四边形 在线等回答


IP属地:美国1楼2015-10-09 09:48回复
    两个for……找下规律呗……


    IP属地:广东来自Android客户端2楼2015-10-09 10:02
    收起回复
      支持


      IP属地:湖北来自Android客户端3楼2015-10-09 10:07
      回复
        这种都是用for循环解决的


        IP属地:广东来自Android客户端4楼2015-10-09 10:08
        收起回复
          println


          5楼2015-10-09 10:12
          回复
            package com.java;
            import java.util.Scanner;
            public class Test {
            public static void main(String[] args){
            Scanner input =new Scanner(System.in);
            System.out.println("How long do you want side to be?");
            int row=input.nextInt();
            System.out.println("Please enter the character you want it to be made of:");
            String str=input.next();
            if(row>1){
            for (int i = 0; i < row; i++) {
            for (int j = 0; j <= i; j++) {
            if( i >=2 && j !=0 && j!=i){
            System.out.print(" ");
            }else{
            System.out.print(str);
            }
            }
            System.out.println();
            }
            for (int i =0; i<row-1; i++) {
            for (int j = 0; j <= i; j++) {
            System.out.print(" ");
            }
            for (int j = row-1; j >i; j--) {
            if(j==row-1 || j==i+1){
            System.out.print(str);
            }else{
            System.out.print(" ");
            }
            }
            System.out.println();
            }
            }else{
            System.out.println("至少为2!");
            }
            }
            }


            IP属地:北京10楼2015-10-09 14:41
            收起回复