Java 识别多个字符
我对编码非常陌生,似乎不知道如何让它打印我知道的烘焙名称,因为它试图识别一个单数字符,但我不知道如何让它识别多个字符Java 识别多个字符,java,Java,我对编码非常陌生,似乎不知道如何让它打印我知道的烘焙名称,因为它试图识别一个单数字符,但我不知道如何让它识别多个字符 public static void main(String[] args) { int ingredients = 5+4+9+8+201+200+202+2+1+203; char bake; if (ingredients >= 835) { bake = 'Cookies'; } else if (ingredie
public static void main(String[] args) {
int ingredients = 5+4+9+8+201+200+202+2+1+203;
char bake;
if (ingredients >= 835) {
bake = 'Cookies';
} else if (ingredients >= 80) {
bake = 'C';
} else if (ingredients >= 70) {
bake = 'B';
} else if (ingredients >= 60) {
bake = 'D';
} else {
bake = 'W';
}
System.out.println("You can make " + bake);
}
在
Java
中,您可以区分char
和String
int ingredients = 5+4+9+8+201+200+202+2+1+203;
String bake;
if (ingredients >= 835) {
bake = "Cookies";
} else if (ingredients >= 80) {
bake = "C";
} else if (ingredients >= 70) {
bake = "B";
} else if (ingredients >= 60) {
bake = "D";
} else {
bake = "W";
}
System.out.println("You can make " + bake);
是一个字符,位于简单引号之间,如char
'a'
是双引号之间的一对多字符集,如String
“Cookies”
Cookies
您需要一个字符串
int ingredients = 5+4+9+8+201+200+202+2+1+203;
String bake;
if (ingredients >= 835) {
bake = "Cookies";
} else if (ingredients >= 80) {
bake = "C";
} else if (ingredients >= 70) {
bake = "B";
} else if (ingredients >= 60) {
bake = "D";
} else {
bake = "W";
}
System.out.println("You can make " + bake);
对变量使用
String
而不是char
,bake
例如
String bake = "some value";
数据类型
char
用于保存单个字符。要保存多个字符,需要使用数据类型String
,最好从总结主要问题的答案开始。然而,你也应该写一些例子来解释。它永远不会迟到,所以编辑和改进你的答案。我已经进步了,现在看起来好多了。坚持下去!