-2

I am trying to create a method for my program that, when called, will ask you to press enter to continue. However, BlueJ gives me an error message saying ' expected'. Below is my code

Note: the continue class hasn't been fully finished yet.


import java.util.Scanner;

public class BlackjackRunner

{

   public static void main (String[]args)

   {

       System.out.print("Ready to play Blackjack(y/n)? =====> ");
       Scanner input = new Scanner(System.in);
       String response = input.nextLine();
       System.out.println();
       if(response.charAt(0) != 'y' || response.charAt(0)!= 'Y')
            System.out.println("Too bad, you play");
       else
            System.out.println("Good.");  


   }

   public static void*** continue()

   {

       System.out.println("-----PRESS ENTER TO CONTINUE-----");
       Scanner wait = new Scanner(System.in);

   }

}

BlueJ gives an error message after the void statement (where the *** is). I am not exactly sure why this is incorrect. If someone could explain/help, that would be wonderful.

Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • 1
    Please look at the edits I made to your post to learn how to format. – Jim Garrison Dec 01 '17 at 17:40
  • "continue" is a reserved keyword. Always pay attention to your editor's formatting: BlueJ has syntax highlighting, so everything that comes in blue is a keyword. If you look at your code inside the IDE, you'll notice that "continue" is blue. It means it is a keyword, and keywords cannot be used as class/method/variable names. – BackSlash Dec 01 '17 at 17:47

5 Answers5

5

continue is a reserved keyword in Java, change the method name. Here's a list of other reserved keywords: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

devgianlu
  • 1,547
  • 13
  • 25
3

The word continue is a reserved word in Java and cannot be used as the name of a method, class or variable. Use a different name.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
0

You can not name your method "continue" as continue is a reserved keyword(used in loops). You can name it continueGame, or that sort, but it may not be a reserved keyword.

Your error tells you this, it is saying you need an identifier. In Java's mind, there's no name for the function.

King Twix
  • 52
  • 8
0

Your source file should not compile if using reserved words like continue as identifier. Better if you just compile the source before running the same. Just change the method name to something other than continue and it will work

Har Krishan
  • 273
  • 1
  • 11
0

You need to rename your method from continue to continueBlackJack or something of that sort because continue is kept away from being used in Java. Also, I would recommend just using Oracle JDK for learning because the *** appears harder than java in general imo.

kixkid229
  • 1
  • 1