4 回答
TA貢獻1863條經驗 獲得超2個贊
這在 Java 中是不可能的。Switch 旨在識別獨特的案例。
PS - 因為,你正在使用 android,試試 Kotlin。您可以使用 when 在 kotlin 中實現它(基本上是switch 但具有 superpowers)。例如:
when(bpay) {
in 40000..55000 -> println("Your Job is Clerk")
in 55000..65000 -> println("Your Job is Accoutant")
//Similarly for the rest
}
TA貢獻1851條經驗 獲得超4個贊
如前所述,這是不可能的。而是使用if-else-if:
if ( bpay <= 90000 && bpay >= 85000 ) {
System.out.println("You Job is General Manager");
} else if( bpay <= 84999 && bpay >= 75000 ) {
System.out.println("Your Job is Manager" );
} else if ( bpay <= 74999 && bpay >= 65000 ) {
System.out.println("Your Job is Assistant Manager ");
} else if ( bpay <= 64999 && bpay >= 55000 ) {
System.out.println("Your Job is Accoutant");
} else if( bpay <= 54999 && bpay >= 40000 ) {
System.out.println("Your Job is Clerk");
} else if( bpay < 40000 ) {
System.out.println("You Job is Security Incharge");
}
添加回答
舉報
