我怎样才能让toString()返回一个多行字符串? [英] How can I have toString() return a multi-line string?

查看:162
本文介绍了我怎样才能让toString()返回一个多行字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个程序,该程序搜索数组并找到最小值,然后输出跑步者的时间,firstName和lastName。

I'm working on a program that searches through an array and finds the smallest value and then prints out the time, firstName, and lastName of the runner.

我需要弄清楚的是如何在不同的行上返回三个值,如:

What I need to figure out is how to return the three values on separate lines, something like:

public String toString() {
    return String.format( firstName + " " +  lastName + " " + Time );
}

这就是我现在所拥有的

有没有办法让三个值在不同的行上打印出来?

Is there a way to have the three values print out on separate lines?

推荐答案

试试这个

public String toString(){ return String.format( firstName + ".%n " + lastName + ".%n " + Time);

这篇关于我怎样才能让toString()返回一个多行字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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