我正在尝试生成一个数字来执行 switch 语句,但它没有生成正确的结果。但是当删除 IF 块时,它可以正常工作。代码中的问题是什么?
import static java.lang.Character.isDigit;
public class TrySwitch
{
enum WashChoise {Cotton, Wool, Linen, Synthetic }
public static void main(String[]args)
{
WashChoise Wash = WashChoise.Cotton;
int Clothes = 1;
Clothes = (int) (128.0 * Math.random());
if(isDigit(Clothes))
{
switch (Clothes)
{
case 1:
System.out.println("Washing Shirt");
Wash = WashChoise.Cotton;
break;
case 2:
System.out.println("Washing Sweaters");
Wash = WashChoise.Wool;
break;
case 3:
System.out.println("Socks ");
Wash = WashChoise.Linen;
break;
case 4:
System.out.println("washing Paints");
Wash = WashChoise.Synthetic;
break;
}
switch(Wash)
{
case Wool:
System.out.println("Temprature is 120' C "+Clothes);
break;
case Cotton:
System.out.println("Temprature is 170' C "+Clothes);
break;
case Synthetic:
System.out.println("Temprature is 130' C "+Clothes);
break;
case Linen:
System.out.println("Temprature is 180' C "+Clothes);
break;
}
}
else{
System.out.println("Upps! we don't have a digit, we have :"+Clothes );
}
}
}