2015-10-14 60 views
-1

IM嗨這裏新和相當新的Java在學校香港專業教育學院有一個程序在這裏,Ive得到工作了剛纔打印它應該她的節目的方式如何打印出一列VS一排

import java.util.*; 
public class stars 
{ 
    public static void main(String args[]){ 
    Scanner keyboard = new Scanner(System.in); 
    System.out.print("Enter the starting Value"); 

    for(int star=keyboard.nextInt(); star>=1; star--) 
    { for(int starTwo=star;starTwo>=1; starTwo--) 
     { 
     System.out.println("*"); 
    } 
    } 

    }  
} 

它現在打印在一個直列中,它有正確的數字「*」,只是格式錯誤。 我需要它所以第7行有7,第6行有6行5有5等。一路爲1.

預先感謝您。

+0

向我們展示你的輸入,預期的結果,預計輸出 –

+0

請理解的System.out.println意味着打印到一個新行。 您需要使用System.out.print(「*」); – Acewin

回答

1

你的問題是重複的,請通過這個How can I print to the same line?

請理解 的System.out.println意味着打印到一個新行。

您需要使用 System.out.print(「*」);

for (int star = keyboard.nextInt(); star >= 1; star--) { 
    System.out.println(""); 
    for (int starTwo = star; starTwo >= 1; starTwo--) { 
     System.out.print("*"); 
    } 
} 

for (int star = 7; star >= 1; star--) { 
    System.out.println(""); 
    for (int starTwo = star; starTwo >= 1; starTwo--) { 
     System.out.print("*"); 
    } 
} 

打印

*******  
****** 
***** 
**** 
*** 
** 
* 
+0

這隻打印出一行是,但不喜歡我想我說我需要這樣,當輸入是說7它打印一排7,然後一個新的6行,然後一個新的5行ect一路到一行1. – Comradedrago

+0

你我的朋友甚至沒有檢查代碼結果 – Acewin

+0

謝謝你錯過了你改變的代碼行。 – Comradedrago