두 개의 중첩 된 스위치가 있고 다른 스위치의 경우 하나의 스위치 케이스의 값을 사용하고 싶습니다. 아래 예제처럼 double 변수 temp_usr을 사용하여 다른 스위치의 (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: .........
이걸 시도하면 어떻게됩니까? 쉽게 읽을 수 있도록 서식을 수정하는 것이 좋습니다. –
'switch1'이 2이지만'switch2'가 1이라면 어떻게 될까요? –
질문을받지 못했습니다. 설명 해주십시오. – freetiger