String array combined with if-then-else to output different text for different values
Howdy,
I want to create a String type array of values, then select and print a value in the array based on a pre-determined value (door is open or closed) using if-then-else.
Here is what I have
Code :
class Door {
public static void main(String[] JD) {
int door = 0; //1 is open, 0 is closed
String[] word = {"open", "closed"};
if (door = 1) {
word = 0;
}
else if (door = 0) {
word = 1;
}
System.out.println("Door = " + word);
}
}
When I try to compile, it gives four incompatible types errors.
It says I need to use boolean operators instead of int,
and that are in int type, but they should be in java.lang.String[] form.
So, obviously boolean would instead of int for this, but I want to use int so that I can later make a more complex code with more variables.
What is the proper format to input the "word" values? I have tried "0" and [0], neither of which work.
This is pissin me off,
any help will be greatly appreciated
Re: String array combined with if-then-else to output different text for different va
Code :
class Door {
public static void main(String[] args) {
int door = 0; //1 is open, 0 is closed
String[] word = {"open", "closed"};
System.out.println("Door = " + word[door]);
}
}