So I have two classes:
class ConcatTesting{
public static void main(String args[]) throws java.io.IOException{
char inLetter;
String input="";
//This loops takes line of cmd and makes the input variable into that string
for(;;){
inLetter=(char) System.in.read(); //get next char
//if the line hasn't ended then add that char to input
if(inLetter!='\n'){
input+=String.valueOf(inLetter);
}else{
//other wise line has ended so input is finished
break;
}
}
//removes extra white-spaces
input.trim();
//test what input is to make sure it is working correctly
System.out.println(input);
//test concat function
UseConcat.ask(input);
UseConcat.ask("pie");
}
}
class UseConcat{
public static void ask(String str){
System.out.println("What does " + str +" mean?");
}
}
In the program I call the static method UseConcat.ask(String str)
twice.
When the argument in the UseConcat.ask(String str)
is the input
variable, the concatenation seems to fail. However, when I call UseConcat.ask(String str)
with the argument being a random string, the concatenation works.
The input
variable is the first written line of the cmd converted to a string.
Here is an example image.
As shown in the image, the input variable is set to WOA.
However UseConcat.ask(input);
prints out mean?oes WOA intsead of What does WOA mean?
When input is printed: System.out.println(input);
it prints WOA as normal.
On the other hand when I call UseConcat.ask("pie");
It works and prints: What does pie mean?