how to use value of one switch case in another switch case: value is
Scanner inputs?
I have two nested switches and I wanted to use value of one switch case in
another switch case. As in the below example, I wanted to use the double
variable temp_usr and pass it as an argument to a method (cels()) in the
another switch case, how can I do this?
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: .........
No comments:
Post a Comment