如何使用System.out.println打印方法的结果 [英] How to print the result of a method with System.out.println
本文介绍了如何使用System.out.println打印方法的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打印出方法的结果?我想打印出翻译的返回但它显示为true或false。建议请。
How do I print out the result of a method? I want to print out the return of translate but it displays true or false. Suggestions please.
/**
* @returns the string "yes" if "true" and "no" if false
*/
public String translate(boolean trueOrFalse)
{
if(pback == true)
{
return "yes";
}
else
{
return "no";
}
}
/**
* Display book info
*/
public void displaybook()
{
System.out.println("Title: " + title);
System.out.println("Author: " + author);
System.out.println("ISBN: " + isbn);
System.out.println("Pages: " + pages);
System.out.println("Paperback: " + pback);
System.out.println("Suggested Price: " + price);
}
推荐答案
看起来你错误地连接起来了您的变量 pback
而不是以下语句中的translate方法的结果:
It looks like you mistakenly concatenated your variable pback
instead of the result of your translate method in the following statement:
System.out.println("Paperback: " + pback);
相反,将该语句替换为
System.out.println("Paperback: " + translate(pback));
这篇关于如何使用System.out.println打印方法的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文