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

,最好从总结主要问题的答案开始。然而,你也应该写一些例子来解释。它永远不会迟到,所以编辑和改进你的答案。我已经进步了,现在看起来好多了。坚持下去!