3
因此,我对编程相当陌生,并且刚刚在学校开始上课。我们被告知要制作一个程序,只使用变量类型char,int,byte,float和boolean来打印:“H3110 wor1d 2.0 true”。这是我能够想出的。无法将原始类型值连接成字符串
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);
}
}
但是,当我尝试运行它时,我总是收到错误消息。
String x = (ab + cd + ef + gh + ig + l + d + mn + op + qr);
^
first type: float
second type: boolean
1 error
我不知道我在做什么错,并想知道是否有更简单的方法来编写这个程序。我是不是真的比它更复杂?
或者更简单地说,使用多个打印语句。 – chrylis