':' turning into label statement

Status
Not open for further replies.

redhat

Mad and Furious
I use the BlueJ compiler to write and run Java programmes.
(I'm in school, n d board prescribes that :p)
While writing a program, i experianced an unusual error, whenever I type ":", it turns into a label statement, and I cant use it for declaring cases in Switch...

Code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/**
 * Write a description of class Designs here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Designs
{

    public static void main(String[] args) throws IOException
    {
        boolean cont = true;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        do
        {
            loop:cont = true;
            System.out.println("/fWelcome to the Designs Class...");
            System.out.println("01. Design 01");
           
            System.out.print("Please Select an option : ");
            try
            {
                int opt = Integer.parseInt(br.readLine());
            }
            catch(Exception oe)
            {
                System.out.println("Error in input :/n" + oe);
                break;
            }
            Switch(opt);
            {
                case 1:
                System.out.println();
                default:
                break loop;
            }
        } while(cont);
    }
}
PS I have removed some parts of the code.

ERROR:
Code:
Designs.java:46: orphaned case
                case 1:
                ^
Designs.java:48: orphaned default
                default:
                ^
2 errors

Can someone please help?

THREAD CLOSED...

Sorry, I found my error:
I was referencing to variable opt, which was out of scope
Its limited to the try block...:rolleyes:
 
Last edited:
Status
Not open for further replies.
Top Bottom