2015-10-14 57 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