java中boolean的问题
来源:百度知道 编辑:UC知道 时间:2024/09/28 15:14:30
public class ryg{
private final int RED = 1;
private final int YELLOW = 2;
private final int GREEN = 3;
private int color;
public ryg() {
color = RED;
}
public void change() {
if (color == RED) {
color = GREEN;
} else if (color == YELLOW) {
color = RED;
} else if (color == GREEN) {
color = YELLOW;
}
}
public String drawLamps() {
if (color == RED) {
return "(R) ( ) ( )";
} else if (color == GREEN) {
return "( ) ( ) (G)";
} else if (color == YELLOW) {
return "( ) (Y) ( )";
} else {
return " ** Error ** ";
}
}
public void draw() {
System.out.println( "[" + drawLamps() + "]");
}
}
class Testryg{
public static void main(String[] args){
ryg t = new ryg();
private final int RED = 1;
private final int YELLOW = 2;
private final int GREEN = 3;
private int color;
public ryg() {
color = RED;
}
public void change() {
if (color == RED) {
color = GREEN;
} else if (color == YELLOW) {
color = RED;
} else if (color == GREEN) {
color = YELLOW;
}
}
public String drawLamps() {
if (color == RED) {
return "(R) ( ) ( )";
} else if (color == GREEN) {
return "( ) ( ) (G)";
} else if (color == YELLOW) {
return "( ) (Y) ( )";
} else {
return " ** Error ** ";
}
}
public void draw() {
System.out.println( "[" + drawLamps() + "]");
}
}
class Testryg{
public static void main(String[] args){
ryg t = new ryg();
public class ryg{
private boolean RED = true;
private boolean YELLOW = false;
private boolean GREEN = false;
public ryg() {
this.RED = true;
}
public void change() {
if (this.RED) {
this.GREEN = true;
this.RED = false;
} else if (this.YELLOW) {
this.RED = true;
this.YELLOW = false;
} else if (this.GREEN) {
this.YELLOW = true;
this.GREEN = false;
}
}
public String drawLamps() {
if (this.RED) {
return "(R) ( ) ( )";
}
if (this.GREEN) {
return "( ) ( ) (G)";
}
if (this.YELLOW) {
return "( ) (Y) ( )";
}
return " ** Error ** ";
}
public void draw() {
System.out.println( "[" + drawLamps() + "]");
}
}
class Testryg{
public static void main(S