Failed to concatenate primitive type values into a String

Viewed 441

So I'm fairly new to programming and I just started taking a class at school. We were told to make a program that will print:" H3110 wor1d 2.0 true " only using the variable types char, int, byte, float, and boolean. This is what I was able to come up with.

public class Homework3 {

  public static void main(String[] args) {

    char ab = 'H';
    int cd = 3110;

    char ef = 'w' ;
    byte gh = 0;
    char ig = 'r'; 
    char l = '1'; 
    char d = 'd';
    float mn = 2.0f;
    char op = ' ' ;
    boolean qr = false;



   String x = (ab + cd + ef + gh + ig + l + d + mn + op + qr);
   System.out.println(x);
 }
}   

However, I keep getting an error message when I try to run it through.

  String x = (ab + cd + ef + gh + ig + l + d + mn + op + qr);
                                                    ^
 first type:  float
 second type: boolean
1 error

I don't know what I'm doing wrong and was wondering if there's an easier way to write this program. Am I making it more complicated than it really is?

1 Answers
Related