Results 1 to 4 of 4
  1. #1
    Zelaine is offline Senior Member
    Join Date
    Aug 2013
    Location
    Sweden
    Posts
    157
    Rep Power
    2

    Lightbulb Complaining Method

    Hello there! :)
    I just wanted to ask you guys something. I have a method that says that I've got to return a result of the type int, even though that's what I'm doing! Do you know why it does that by looking at my method below?

    Java Code:
    	static int gameDifficulty(){
    		Scanner hej = new Scanner(System.in);
    		char c = 'M';
    		while(c != 'E' && c != 'N' && c != 'H' && c != 'I'){
    			System.out.print("Choose your difficulty:\n\n(E) Easy.\n(N) Normal.\n(H) Hard.\n(I) Impossible.\n\n");
    			c = hej.next().charAt(0);
    			c = capitalizingLetter(c);
    		}
    		switch(c){
    			case 'E':
    				return 8;
    			case 'N':
    				return 6;
    			case 'H':
    				return 3;
    			case 'I':
    				return 1;
    		}
    	}

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,410
    Rep Power
    25

    Default Re: Complaining Method

    Please post copy the full text of the error message and post it here.

    What if a case is NOT selected? How about using a default: to catch that case?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    erprtkjn is offline Member
    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Question Re: Complaining Method

    Hi Zelaine,

    Even i am new to the programming language but i think you need to use break statements after every return.
    As because you cannot have multiple return statements without conditions.
    Please correct me if i am wrong.

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,016
    Rep Power
    6

    Default Re: Complaining Method

    Quote Originally Posted by erprtkjn View Post
    Hi Zelaine,

    Even i am new to the programming language but i think you need to use break statements after every return.
    Guessing is useless and the same as releasing something without testing first: it will be broken. Try it out yourself before posting - you'll see instantly that you are quite wrong.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 7
    Last Post: 04-11-2013, 05:31 AM
  2. Replies: 2
    Last Post: 03-23-2012, 04:53 AM
  3. What is my Timer constructor complaining about ?
    By fatabass in forum New To Java
    Replies: 7
    Last Post: 02-19-2012, 10:11 PM
  4. Replies: 1
    Last Post: 10-27-2011, 07:16 AM
  5. Replies: 1
    Last Post: 10-17-2011, 01:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •