PAT-類比賽--Java-L1-7. 跟奧巴馬一起畫方塊__Java

來源:互聯網
上載者:User
L1-7. 跟奧巴馬一起畫方塊 時間限制 400 ms
記憶體限制 65536 kB
代碼長度限制 8000 B
判題程式 Standard 作者 陳越

美國總統奧巴馬不僅呼籲所有人都學習編程,甚至以身作則編寫代碼,成為美國曆

史上首位編寫電腦代碼的總統。2014年底,為慶祝“電腦科學教育周”正式啟動,奧巴馬編寫了很簡單的電腦代碼:在螢幕上畫一個正方形。現在你也跟他一起畫吧。

輸入格式:

輸入在一行中給出正方形邊長N(3<=N<=21)和組成正方形邊的某種字元C,間隔一個空格。

輸出格式:

輸出由給定字元C畫出的正方形。但是注意到行間距比列間距大,所以為了讓結果看上去更像正方形,我們輸出的行數實際上是列數的50%(四捨五入取整)。 輸入範例:

10 a
輸出範例:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</pre><pre name="code" class="java">import java.util.Scanner;public class Main {  public static void main(String[] args) {    Scanner sc = new Scanner(System.in);    double n = sc.nextInt();    String s = sc.next();    if(3<=n&&n<=21){      double h = n/2;      int x = (int) (n/2);      double y = h-x;      //System.out.print(y);      if(y>=0.5){        h ++;      }      //System.out.println((int)h);      for(int i=0 ;i<(int)h ;i++){        for(int j=0 ;j<n ;j++){          System.out.print(s);        }        System.out.println();      }    }      }}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.