当前位置: 动力学知识库 > 问答 > 编程问答 >

java - How to call a static String method which returns string from main method?

问题描述:

This question already has an answer here:

  • Differences between System.out.printlin() and Return in Java

    3 answers

网友答案:

You aren't getting any output because you aren't actually printing anything. If you want to print something, you'll have to interact with the program's stdout or stderr. E.g.:

public static void print(String str) {
    System.out.print(str);
}
网友答案:

Change the body of print method.

public static void print(String str)
{
  System.out.println(str);
}

You are returning a string value and didn't do anything with it. Send it to println method to print the string by outputting to the console.

网友答案:

Your code looks ok, and you are getting the string in the return of the print method, but since you are not printing it at all is getting lost...

This statement here:

print(stw);

must be replace with somehthing like:

System.out.println(print(stw));
分享给朋友:
您可能感兴趣的文章:
随机阅读: