我有两个嵌套开关,我想在另一个开关案例中使用一个开关案例的值。如下例所示,我想使用双变量temp_usr并将其作为参数传递给另一个 switch 案例中的方法(cels()),我该怎么做?
switch( switch1){
case 1:
{
System.out.println(" You have selected Celsius");
Scanner temp_ip= new Scanner(System.in);
System.out.println("Please enter the temperature in celsius");
double temp_usr= temp_ip.nextDouble();
}
break;
case 2: ...............
case 3: ...............
switch(switch2) {
case 1:
{
System.out.println("convert it into Celsius");
System.out.println(cels(arg)); /*this argument should take value of temp_usr*/
}
break;
case 2: .........
case 3: .........