Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在列与行中打印_Java_Loops - Fatal编程技术网

Java 如何在列与行中打印

Java 如何在列与行中打印,java,loops,Java,Loops,嗨,我是新来的,在学校里对java相当陌生。我这里有一个程序,我刚刚开始工作,它以应该的方式打印程序 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 st

嗨,我是新来的,在学校里对java相当陌生。我这里有一个程序,我刚刚开始工作,它以应该的方式打印程序

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个ect。一直到1号


提前谢谢。

您的问题是重复的,请检查一下

请理解 System.out.println表示打印到新行

你需要使用 系统输出打印(“*”)

范例

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

*******    
******
*****
****
***
**
*

显示您的输入、预期结果、预期输出请理解System.out.println的意思是打印到新行。您需要使用System.out.print(“*”);这只是一行打印出来是的,但不是像我说的那样,我需要这样,当输入为7时,它打印一行7,然后打印一行6,然后打印一行5等,直到一行1。你我的朋友甚至没有检查代码的结果谢谢你错过了你更改的代码行。
*******    
******
*****
****
***
**
*