删除循环Java的空白文本行

删除循环Java的空白文本行,java,for-loop,nested-loops,Java,For Loop,Nested Loops,我正在尝试使用嵌套for循环打印一些时间表,我让它工作了,但我有一个额外的空行,我可以使用if语句删除它,但我想知道是否有更好的方法来执行此操作。输出需要如下所示 12345 2 4 6 8 10 3691215 4 8 12 16 20 5101525 static void timesTables(){ 对于(int i=1;i如果需要该输出,可以添加额外的println static void timesTables(){ for (int i = 1; i <= 5 ; i

我正在尝试使用嵌套for循环打印一些时间表,我让它工作了,但我有一个额外的空行,我可以使用if语句删除它,但我想知道是否有更好的方法来执行此操作。输出需要如下所示

12345
2 4 6 8 10
3691215
4 8 12 16 20
5101525

static void timesTables(){

对于(int i=1;i如果需要该输出,可以添加额外的
println

static void timesTables(){
    for (int i = 1; i <= 5 ; i++){
       for (int j = 1; j <= 5; j++){
           int output = i * j;
           System.out.print(output + (j < 5)? " ": "");
       }
       System.out.println();
   }  
static void timesTables(){

对于(int i=1;i您可以为所需的输出添加额外的println和if条件。在外部for循环的第5次迭代中,不会打印额外的空行

static void timesTables(){
    for (int i = 1; i <= 5 ; i++){
        for (int j = 1; j <= 5; j++){
           int output = i * j;
           System.out.print(output + " ");
       }

       if(i<5)
       System.out.println();
   } 
static void timesTables(){

对于(inti=1;i在其他人已经写过的内容的基础上:

static void timesTables()
{
    int numRows = 5;
    int numCols = 5;
    for ( int i = 1; i <= numRows; i++ )
    {
         for ( int j = 1; j <= numCols; j++ )
         {
            int output = i * j;
            System.out.print( output + ( j < numCols )? " ": "" );
         }

         if( i < numRows )
         {
            System.out.println();
         }
     }
}  
static void timesTables()
{
int numRows=5;
int numCols=5;

对于(int i=1;i在哪里显示额外的空白行?顶部还是底部?或者可能在中间的某个地方?这条线是在命令行或IDE控制台上显示的吗?有时看起来好像有一个新的行,当没有的时候。您发布的代码与输出不匹配,请正确地发布它,您需要的代码行如<代码>/代码>接受值。真的有问题吗?您的代码与此处所述内容之间似乎不匹配。代码没有if,也没有回车符,也没有生成任何输出(i代码和输出不匹配,请在此处发布完整代码)。
static void timesTables()
{
    int numRows = 5;
    int numCols = 5;
    for ( int i = 1; i <= numRows; i++ )
    {
         for ( int j = 1; j <= numCols; j++ )
         {
            int output = i * j;
            System.out.print( output + ( j < numCols )? " ": "" );
         }

         if( i < numRows )
         {
            System.out.println();
         }
     }
}