0

In this below program, am passing a string value as argument to method print(String) which is static and returns string. Though I get no error,am not getting output.

public class StringTest {

    public static void main( String[] args )
    {
        String  stw="iii";
        print(stw);
    }

    public static String print( String str )
    {
        return str;
    }
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350
CodingOwl
  • 156
  • 1
  • 11
  • 1
    what is the error you get? I dont see any issue with your code. even though you are calling the method for nothing. – LeTex Apr 03 '16 at 15:55
  • 4
    Well, you are not printing your output – TheLostMind Apr 03 '16 at 15:55
  • 4
    please don't down vote. this person tried something at least. Is there any standard on stack-overflow that is put as mandatory knowledge level before posting a question ? – LeTex Apr 03 '16 at 15:58
  • 1
    @NamdanAthreya FYI, in the MarkDown syntax used by this StackOverflow site, use four spaces instead of a TAB in your source code sample. I fixed it for you. – Basil Bourque Apr 03 '16 at 16:10

3 Answers3

4

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);
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350
3

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.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
lobo
  • 164
  • 1
  • 6
2

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));
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97