国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網 會員登陸 & 注冊

輸出菱形(非最優(yōu)

2019-11-04 13:36 作者:kands-code  | 我要投稿

//大家好,今天我就給大家講講一個讓初學者十分頭疼的作業(yè)

//包括我,就是輸出一個菱形。

import java.util.*;


public class njava07{

? public static void main(String []args){

? ? Scanner in = new Scanner(System.in);

? ? //我們先造個scanner讀取用戶輸入

? ? //這里,我們特別要求輸入一個奇數

? ? int lineCount = in.nextInt();

? ??

? ? int maxLineNum = (lineCount+1)/2;

? ? //菱形的上部分,多一行

? ? for(int i = 1;i<=maxLineNum;i++)

? ? //循環(huán)菱形數量越來越多的幾行

? ? {

? ? ? for(int space = 1;space <= maxLineNum-i;space++){

? ? ? ? System.out.print("? ");//輸出空格

? ? ? }

? ? ? for(int star = 1;star<=(i*2)-1;star++){

? ? ? ? System.out.print("* ");//輸出星星

? ? ? }

? ? ? System.out.println();//滿足條件,換行

? ? }

? ??

? ? int declineCount = lineCount - maxLineNum;

? ? //計算剩下的

? ? for(int i = 1;i<=declineCount;i++){

? ? ? for(int space = 1;space <= i;space++){

? ? ? ? System.out.print("? ");

? ? ? }

? ? ? for(int star = 1;star <= 2*(declineCount-i+1)-1;star++)

? ? ? //經過調試,發(fā)現(xiàn)是下面星星多輸出了一個;改正了,繼續(xù)看看。

? ? ? {

? ? ? ? System.out.print("* ");

? ? ? }

? ? ? System.out.println();

? ? }

? }

}


輸出菱形(非最優(yōu)的評論 (共 條)

分享到微博請遵守國家法律
澄城县| 闻喜县| 安溪县| 临潭县| 赤壁市| 措美县| 将乐县| 徐汇区| 潼南县| 龙岩市| 银川市| 成武县| 边坝县| 宁海县| 荃湾区| 旬阳县| 北宁市| 丰顺县| 佛坪县| 白朗县| 靖宇县| 区。| 信丰县| 甘谷县| 淮北市| 闸北区| 卓尼县| 临潭县| 阿勒泰市| 綦江县| 城固县| 广水市| 屏东县| 怀集县| 元阳县| 阜阳市| 文山县| 遂宁市| 密山市| 兴山县| 象山县|