How to Add a Number and a String in Java


In this example, we will learn you that if you add a number and a string, the result will be a string concatenation in Java.

Source Code

package com.beginner.examples;

public class AddNumberAndString {
  public static void main(String[] args) {
    String a = "7";
    int b = 11;
    String c = a + b; // add a number and a string
    System.out.println(c);
  }
}

Output:

711
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments