How do I concatenate two strings in Java?

前端 未结 23 3385
长情又很酷
长情又很酷 2020-11-22 04:47

I am trying to concatenate strings in Java. Why isn\'t this working?

public class StackOverflowTest {  
    public static void main(String args[]) {
                


        
23条回答
  •  长发绾君心
    2020-11-22 05:05

    here is an example to read and concatenate 2 string without using 3rd variable:

    public class Demo {
        public static void main(String args[]) throws Exception  {
            InputStreamReader r=new InputStreamReader(System.in);     
            BufferedReader br = new BufferedReader(r);
            System.out.println("enter your first string");
            String str1 = br.readLine();
            System.out.println("enter your second string");
            String str2 = br.readLine();
            System.out.println("concatenated string is:" + str1 + str2);
        }
    }
    

提交回复
热议问题