Q:

String concatenation with primitive data type values in Java

belongs to collection: Java String Programs

0

String concatenation with primitive data type values in Java

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Java code for string concatenation with primitive data type values

// 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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to find occurrences of palindrome wor... >>
<< String comparison using Collator and String classe...