I was writing a piece of code to reverse a String wordwise(Input:Java is fun; Output:fun is Java), when I came across a question:How can a String variable be added to a character type variable.the code is working perfectly, but how is this possible? Someone, please explain this to me. Thanks in advance.
import java.io.*;
public class numberof {
public static void main(String args[])throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str1,str2="",str3="";
str1=br.readLine()+" ";
for(int i=0;i<str1.length();i++){
char x=str1.charAt(i);
if(x==' '){
str2=str3+" "+str2;
str3="";
}
else{
str3=str3+x; //HERE IS THE QUESTION PART(STRING+CHAR)
}
}
System.out.println(str2);
}
}