Switch Statement

+1 Rachael Laurence · February 26, 2015
Bucky I follow you to the letter and keep getting an error, what am I doing wrong? I have been doing this since 5pm and it is now 1AM, please help!!! I am pulling out my hair!

class Kids {
    public static void main(String args[]) {
        int age;
        age = 3;
            
        switch (age) {
        case 1:
            System.out.println("you can crawl");
            break;
        case 2:
            System.out.println("you can talk");
            break;
        case 3:
            System.out.println("you get in trouble");
            break;
        default:
            System.out.println("I dont know how old you are");
            break;
                
         }
      }
 }                     
                           


Post a Reply

Replies

Oldest  Newest  Rating
0 Developer John · February 26, 2015
Sometimes Eclipse shouldn't work the way it was developed. I've been hearing about strange or uncalled errors once people  create a lower cased named class. 
0 Ignacio Sánchez Casla · February 26, 2015
You put the "[]" in the wrong place

You fix the problem by writing it that way:
public static void main ( String [] args){
0 Bernard Pyc0d333 Parah · February 26, 2015
I also think the code should run, could be your configurations.
Thing is, you are supposed to share your errors.
0 Rachael Laurence · February 27, 2015
All it says is do I wish to proceed with the errors and when I do I get nothing. I tried moving the brackets and had my daughter look over the code to see what I did wrong and she doesn't see it either. I keep these in notepad should I ever need to use it again, I really want to do well so I can get this degree. Java doesn't actually start for me until March 1 but I need certification to get a job. (was that TMI or what?) Anyway, heres the revised code and still it will not work

public class Kids{
    public static void main(String []args){
        int age;
        age = 3;
            
        switch (age){
        case 1:
            System.out.println("you can crawl");
            break;
        case 2:
            System.out.println("you can talk");
            break;
        case 3:
            System.out.println("you get in trouble");
            break;
        default:
            System.out.println("I dont know how old you are");
            break;
                
         }
      }
 }                     
                            

    
Thank you all for your help, I really appreciate it
0 Mathias Frits Rørvik · February 28, 2015
Hi!

I copy-pasted your code into a text editor and compiled it. Code works as expected, there is nothing wrong here. Try compiling and running the program in you command prompt.
0 Bernard Pyc0d333 Parah · February 28, 2015
same  code works. Guess its just java config issues. Have you tried running other codes?  or you can rename the file and try 
  • 1

Java / Android Development

107,067 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator