0

About Method Return with String var

Public static BST1(String var1, String var2){ System.out.println (var1 + "\n" + var2);} This code have not a setted return, i want call this Method with 2 arg Strings and return this 2 (var1,var2) I was trying to build a Methods to get a kind of talking secuence, where every Method Will be a piece of talking between two peoples. No Matter at all, i want to know if im able to return two var from a String Method, and how to do It. Thanks for talking your time.

24th Oct 2019, 11:35 PM
HernĂĄn Enriquez
HernĂĄn Enriquez - avatar
4 Answers
+ 3
A method can return only one variable. But for your two Strings you can use System.lineSeparator() String s = "hello" + System.lineSeparator() + "world"; System.out.println(s); Output: hello world https://code.sololearn.com/ch1iXXA4oeB4/?ref=app
25th Oct 2019, 12:47 AM
Denise Roßberg
Denise Roßberg - avatar
+ 3
Jay Matthews I have read that System.lineSeparator() is platform independent. I am not sure about "\n".
25th Oct 2019, 9:47 AM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thanks very helpful
25th Oct 2019, 12:53 AM
HernĂĄn Enriquez
HernĂĄn Enriquez - avatar
0
I was wondering about this. But i found intresting this sentence at this moment both worths good. I didnt know about this Method, i Guess i Will find It useful at some point.
25th Oct 2019, 2:02 AM
HernĂĄn Enriquez
HernĂĄn Enriquez - avatar