String Concatenation With Primitive Data Type Values in Java

You are currently viewing String Concatenation With Primitive Data Type Values in Java

String concatenation with primitive data type values in Java

// Java code for string concatenation with 
// primitive data type values

public class Main {
    public static void main(String[] args) {
        boolean isMarried = false;
        boolean isQualified = true;
        int age = 21;
        double weight = 67.85;
        char gender = 'M';
        String name = "Shivang Yadav";
        String result = null;

        result = "isMarried: " + isMarried;
        System.out.println(result);

        result = "isQualified: " + isQualified;
        System.out.println(result);

        result = name + " is " + age + " years old.";
        System.out.println(result);

        result = name + " weight is " + weight + " kg.";
        System.out.println(result);

        result = "His gender is: " + gender;
        System.out.println(result);
    }
}

Output

isMarried: false
isQualified: true
Shivang Yadav is 21 years old.
Shivang Yadav weight is 67.85 kg.
His gender is: M

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply