在java中以同一行打印 [英] printing in the same line in java

查看:287
本文介绍了在java中以同一行打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Items和3个派生类的基类,在Items基类中,我有一个打印函数,格式为

I have a base class called Items and 3 derived classes, and within the Items base class i have a print function of the form

public void print(){
        System.out.println("ID " + id + " Title " + title + " <" + year + "> ");
    }

在每个派生类中,我通过<$ c $调用Items打印函数c> super.print(); ,后跟与派生类相关的特定打印功能。

and within every derived class I call the Items print function through super.print(); which is followed by a specific print function relating to the derived class.

我的问题是,无论何时从其中一个派生类执行打印,打印文本都不在同一行。所以 super.print()将在派生类打印函数上方的行中。如何让它们在同一条线上?

My problem is, whenever the printing is executed from one of the derived classes the printed text is not on the same line. So super.print() will be in the line above the derived class print function. How do I get them both to be on the same line?

推荐答案

不要做 println 在基类上使用 print 而不是

Do not do println on the base class use print instead

这篇关于在java中以同一行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆