2017-06-03 44 views
-2
public enum Color { 
    Red, Orange, Yellow, Green, Cyan, Blue, Purple; 


    private boolean isRGB(Color color) 
    { 


    boolean b; 

    switch(color){ 
     case Red: 
      System.out.println("Monday is a work day!!"); 
      break; 
     case Orange: 
      System.out.println("Tusday is a work day!!"); 
     case Yellow: 
      System.out.println("Wednesday is a work day!!"); 
     case Green: 
      System.out.println("Thursday is a work day!!"); 
     case Cyan: 
      System.out.println("Friday is a work day!!"); 
     default: b = false; 

     System.out.println("Sorry this is not a working day!!\nn"); 
     System.out.println("It's weekend!!!"); 
    } 
    return(b); 
} 

这是我自己试过的代码。 我在返回(b)中有一个错误,说'b'没有初始化....请帮助。哪一个是线性和二进制搜索的效率

+0

有人能帮我弄清楚我做错了什么! –

+0

这是运动问题,如果需要它......“”........编写一个程序来检查它是否是三种原色之一(红绿蓝,RGB。星期一,星期二......星期五是工作日 –

+3

这与你的问题的标题有什么关系? –

回答

1

更换

boolean b; 

boolean b = true; 
+2

@TobiasWürth:同样,对于局部变量也是不真实的。只有*字段*默认初始化 –

+0

你是对的,我的错误我不知道 –

-2

public enum Color{//...... - 老师加入了点,但什么也没有问补充。

public enum Color { 
    Red, Orange, Yellow, Green, Cyan, Blue, Purple;  
} 

private boolean isRGB(Color color) { 

    boolean b = false; 

    switch (color) {// i supposed to fill the blank switch(  ) 
     //And also i supposed write all the statements for switch, thats all was required me to do!! 
     case Red: 
      System.out.println("Monday is a work day!!"); 
      break; 
     case Orange: 
      System.out.println("Tusday is a work day!!"); 
      break; 
     case Yellow: 
      System.out.println("Wednesday is a work day!!"); 
      break; 
     case Green: 
      System.out.println("Thursday is a work day!!"); 
      break; 
     case Cyan: 
      System.out.println("Friday is a work day!!"); 
      break; 

     default: 
      b = false; 

      System.out.println("Sorry this is not a working day!!\nn"); 
      System.out.println("It's weekend!!!"); 

    } 
    return (b); 
} 
+2

这不是问题的答案如果你想编辑你的问题,点击“编辑”链接。 –