无法编译java代码

时间:2015-09-01 21:11:43

标签: java compiler-errors

我在Eclipse中为一个简单的二十一点游戏编写了一个程序,它没有任何问题。但是,当我尝试在我的pico编辑器中使用javac进行编译时,它不会编译。为什么Eclipse没有说出编译错误的位置?代码如下。

import java.util.Scanner;

import java.util.Random;

public class Blackjack {

     public static void main(String args[])
     {
         Scanner keyboard = new Scanner(System.in);
         Random randomGenerator = new Random();
         int nextCard;
         boolean keepPlaying = true;
         boolean playAgain = true;
         char hit;
         int DECK_MAX = 10;

         //This is the main loop to play the entire game
         while (playAgain == true)
         {
             int userCard1 = randomGenerator.nextInt(DECK_MAX) + 1;
             int userCard2 = randomGenerator.nextInt(DECK_MAX) + 1;
             int userTotal = userCard1 + userCard2;
             int dealerCard1 = randomGenerator.nextInt(DECK_MAX) + 1;
             int dealerCard2 = randomGenerator.nextInt(DECK_MAX) + 1;
             int dealerTotal = dealerCard1 + dealerCard2;

             //This deals the first two cards to the user, and prints the total
             System.out.println("Welcome to the CCSF Casino! Lets play...");
             System.out.println("Your first cards are " + userCard1 + " and " + userCard2);
             System.out.println("You have a total of " + userTotal);

             //The following checks three scenarios that can end the game on the first deal
             if (userTotal == 21 && dealerTotal == 21) 
             {
                 System.out.println("Both you and the dealer have 21. It's a push.");
                 keepPlaying = false;
             }
             if (userTotal != 21 && dealerTotal == 21)
             {
                 System.out.println("The dealer was dealt 21. You lose.");
                 keepPlaying = false;
             }
             if (userTotal == 21 && dealerTotal != 21)
             {
                 System.out.println("You have 21. You win!");
                 keepPlaying = false;
             }

             //The following checks if the game should continue to user interaction phase, and takes user input if so
             if (keepPlaying == true)
             {
                 System.out.println("The dealer is showing " + dealerCard1 + " with one card face down.");

                 //The following asks the user if they want to keep hitting as long as their total is less than 21
                 while (userTotal < 21)
                 {
                     System.out.println("Would you like another card(y/n)?");
                     hit = keyboard.next().charAt(0);
                     if (hit == 'y')
                     {
                         nextCard = randomGenerator.nextInt(DECK_MAX) + 1; 
                         userTotal += nextCard;
                         System.out.println("You were dealt a " + nextCard + " for a total of " + userTotal);

                         if(userTotal > 21)
                         {
                             System.out.println("You bust and lose. Sorry...");
                             keepPlaying = false;
                             break;
                         }
                     }
                     else
                         break;
                 } 
             }


             //The following checks if the game should continue to the dealer interaction phase. If so, it hits until dealer has > 17
             if (keepPlaying == true)
             {
                 System.out.println("The dealer's current total is " + dealerTotal);

                 while (dealerTotal < 17)
                 {
                     nextCard = randomGenerator.nextInt(DECK_MAX) + 1;
                     dealerTotal += nextCard;
                     System.out.println("Dealer has been dealt a " + nextCard + " for a total of " + dealerTotal);

                     if (dealerTotal > 21)
                     {
                         System.out.println("The dealer busts. You win!");
                         keepPlaying = false;
                         break;
                     }
                 }
             }

             //The following checks if the game should continue into the comparison phase. If so, it determines whether the dealer of user win
             if (keepPlaying == true)
             {
                 if (userTotal > dealerTotal)

                     System.out.println("You win! You had " + userTotal + " and dealer only had " + dealerTotal);

                 if (userTotal  < dealerTotal)
                     System.out.println("You lose...You only had " + userTotal + " and dealer had " + dealerTotal);

                 if (userTotal == dealerTotal)
                     System.out.println("It's a push!");
             }

             System.out.println("Would you like to play again(y/n)?");
             if (keyboard.next().charAt(0) == 'y')
             {   playAgain = true;
                 keepPlaying = true;
             }
             else
             {
                 System.out.println("Don't let the door hit you on the way out!");
                 break;
             }
         }

     }
}

这是我从javac取回的内容

Blackjack.java:23: error: not a statement
total for user
^
Blackjack.java:23: error: ';' expected
total for user
     ^
Blackjack.java:23: error: '(' expected
total for user
         ^
Blackjack.java:23: error: not a statement
total for user
          ^
Blackjack.java:23: error: ';' expected
total for user
              ^
Blackjack.java:24: error: '.class' expected
                         int dealerCard1 =
                             ^
Blackjack.java:24: error: illegal start of expression
                         int dealerCard1 =
                                         ^
Blackjack.java:24: error: ')' expected
                         int dealerCard1 =
                                          ^
Blackjack.java:25: error: illegal start of expression
randomGenerator.nextInt(DECK_MAX) + 1; //first card for dealer
               ^
Blackjack.java:25: error: ';' expected
randomGenerator.nextInt(DECK_MAX) + 1; //first card for dealer
                       ^
Blackjack.java:25: error: variable declaration not allowed here
randomGenerator.nextInt(DECK_MAX) + 1; //first card for dealer
                ^
Blackjack.java:25: error: not a statement
randomGenerator.nextInt(DECK_MAX) + 1; //first card for dealer
                        ^
Blackjack.java:25: error: ';' expected
randomGenerator.nextInt(DECK_MAX) + 1; //first card for dealer
                                ^
Blackjack.java:32: error: ';' expected
prints the total
          ^
Blackjack.java:33: error: ';' expected
                         System.out.println("Welcome to the CCSF Casino!
                               ^
Blackjack.java:33: error: unclosed string literal
                         System.out.println("Welcome to the CCSF Casino!
                                            ^
Blackjack.java:33: error: ';' expected
                         System.out.println("Welcome to the CCSF Casino!
                                                                         ^
Blackjack.java:34: error: not a statement
Lets play...");
     ^
Blackjack.java:34: error: ';' expected
Lets play...");
         ^
Blackjack.java:34: error: unclosed string literal
Lets play...");
            ^
Blackjack.java:41: error: ';' expected
end the game on the first deal
       ^
Blackjack.java:41: error: ';' expected
end the game on the first deal
               ^
Blackjack.java:41: error: ';' expected
end the game on the first deal
                         ^
Blackjack.java:41: error: not a statement
end the game on the first deal
                          ^
Blackjack.java:41: error: ';' expected
end the game on the first deal
                              ^
Blackjack.java:43: error: ';' expected
the user and dealer were both dealt 21, it's a push and the game ends
        ^
Blackjack.java:43: error: variable declaration not allowed here
the user and dealer were both dealt 21, it's a push and the game ends
    ^
Blackjack.java:43: error: ';' expected
the user and dealer were both dealt 21, it's a push and the game ends
                   ^
Blackjack.java:43: error: ';' expected
the user and dealer were both dealt 21, it's a push and the game ends
                             ^
Blackjack.java:43: error: not a statement
the user and dealer were both dealt 21, it's a push and the game ends
                              ^
Blackjack.java:43: error: ';' expected
the user and dealer were both dealt 21, it's a push and the game ends
                                   ^
Blackjack.java:43: error: unclosed character literal
the user and dealer were both dealt 21, it's a push and the game ends
                                          ^
Blackjack.java:43: error: not a statement
the user and dealer were both dealt 21, it's a push and the game ends
                                        ^
Blackjack.java:43: error: ';' expected
the user and dealer were both dealt 21, it's a push and the game ends
                                                   ^
Blackjack.java:43: error: ';' expected
the user and dealer were both dealt 21, it's a push and the game ends
                                                           ^
Blackjack.java:43: error: ';' expected
the user and dealer were both dealt 21, it's a push and the game ends
                                                                     ^
Blackjack.java:45: error: unclosed string literal
                                 System.out.println("Both you and the
                                                    ^
Blackjack.java:45: error: ';' expected
                                 System.out.println("Both you and the
                                                                      ^
Blackjack.java:46: error: not a statement
dealer have 21. It's a push.");
       ^
Blackjack.java:46: error: ';' expected
dealer have 21. It's a push.");
           ^
Blackjack.java:46: error: unclosed character literal
dealer have 21. It's a push.");
                  ^
Blackjack.java:46: error: not a statement
dealer have 21. It's a push.");
                ^
Blackjack.java:46: error: ';' expected
dealer have 21. It's a push.");
                           ^
Blackjack.java:46: error: unclosed string literal
dealer have 21. It's a push.");
                            ^
Blackjack.java:50: error: ';' expected
the dealer was dealt 21 and the user wasn't, user loses and the game ends
          ^
Blackjack.java:50: error: variable declaration not allowed here
the dealer was dealt 21 and the user wasn't, user loses and the game ends
    ^
Blackjack.java:50: error: ';' expected
the dealer was dealt 21 and the user wasn't, user loses and the game ends
                    ^
Blackjack.java:50: error: ';' expected
the dealer was dealt 21 and the user wasn't, user loses and the game ends
                               ^
Blackjack.java:50: error: unclosed character literal
the dealer was dealt 21 and the user wasn't, user loses and the game ends
                                         ^
Blackjack.java:50: error: ';' expected
the dealer was dealt 21 and the user wasn't, user loses and the game ends
                                                       ^
Blackjack.java:50: error: ';' expected
the dealer was dealt 21 and the user wasn't, user loses and the game ends
                                                               ^
Blackjack.java:50: error: ';' expected
the dealer was dealt 21 and the user wasn't, user loses and the game ends
                                                                         ^
Blackjack.java:52: error: unclosed string literal
                                 System.out.println("The dealer was dealt
                                                    ^
Blackjack.java:52: error: ';' expected
                                 System.out.println("The dealer was dealt
                                                                          ^
Blackjack.java:53: error: ';' expected
21. You lose.");
            ^
Blackjack.java:53: error: unclosed string literal
21. You lose.");
             ^
Blackjack.java:57: error: ';' expected
the user got 21 and the dealer didn't, user wins and game ends
        ^
Blackjack.java:57: error: variable declaration not allowed here
the user got 21 and the dealer didn't, user wins and game ends
    ^
Blackjack.java:57: error: not a statement
the user got 21 and the dealer didn't, user wins and game ends
         ^
Blackjack.java:57: error: ';' expected
the user got 21 and the dealer didn't, user wins and game ends
            ^
Blackjack.java:57: error: ';' expected
the user got 21 and the dealer didn't, user wins and game ends
                       ^
Blackjack.java:57: error: unclosed character literal
the user got 21 and the dealer didn't, user wins and game ends
                                   ^
Blackjack.java:57: error: ';' expected
the user got 21 and the dealer didn't, user wins and game ends
                                                ^
Blackjack.java:57: error: ';' expected
the user got 21 and the dealer didn't, user wins and game ends
                                                         ^
Blackjack.java:57: error: not a statement
the user got 21 and the dealer didn't, user wins and game ends
                                                          ^
Blackjack.java:57: error: ';' expected
the user got 21 and the dealer didn't, user wins and game ends
                                                              ^
Blackjack.java:59: error: unclosed string literal
                                 System.out.println("You have 21. You
                                                    ^
Blackjack.java:59: error: ';' expected
                                 System.out.println("You have 21. You
                                                                      ^
Blackjack.java:60: error: unclosed string literal
win!");
    ^
Blackjack.java:60: error: not a statement
win!");
   ^
Blackjack.java:65: error: ';' expected
continue to user interaction phase, and takes user input if so
           ^
Blackjack.java:65: error: ';' expected
continue to user interaction phase, and takes user input if so
                            ^
Blackjack.java:65: error: not a statement
continue to user interaction phase, and takes user input if so
                             ^
Blackjack.java:65: error: ';' expected
continue to user interaction phase, and takes user input if so
                                  ^
Blackjack.java:65: error: ';' expected
continue to user interaction phase, and takes user input if so
                                             ^
Blackjack.java:65: error: ';' expected
continue to user interaction phase, and takes user input if so
                                                        ^
Blackjack.java:65: error: '(' expected
continue to user interaction phase, and takes user input if so
                                                           ^
Blackjack.java:65: error: ')' expected
continue to user interaction phase, and takes user input if so
                                                              ^
Blackjack.java:68: error: unclosed string literal
                                 System.out.println("The dealer is showing
                                                    ^
Blackjack.java:68: error: ';' expected
                                 System.out.println("The dealer is showing
                                                                           ^
Blackjack.java:69: error: ';' expected
" + dealerCard1 + " with one card face down.");
                            ^
Blackjack.java:69: error: ';' expected
" + dealerCard1 + " with one card face down.");
                                      ^
Blackjack.java:69: error: unclosed string literal
" + dealerCard1 + " with one card face down.");
                                            ^
Blackjack.java:69: error: not a statement
" + dealerCard1 + " with one card face down.");
                                           ^
Blackjack.java:72: error: ';' expected
want to keep hitting as long as their total is less than 21
       ^
Blackjack.java:72: error: ';' expected
want to keep hitting as long as their total is less than 21
                    ^
Blackjack.java:72: error: not a statement
want to keep hitting as long as their total is less than 21
                     ^
Blackjack.java:72: error: ';' expected
want to keep hitting as long as their total is less than 21
                       ^
Blackjack.java:72: error: ';' expected
want to keep hitting as long as their total is less than 21
                               ^
Blackjack.java:72: error: ';' expected
want to keep hitting as long as their total is less than 21
                                           ^
Blackjack.java:72: error: ';' expected
want to keep hitting as long as their total is less than 21
                                                   ^
Blackjack.java:72: error: not a statement
want to keep hitting as long as their total is less than 21
                                                    ^
Blackjack.java:72: error: ';' expected
want to keep hitting as long as their total is less than 21
                                                        ^
Blackjack.java:75: error: unclosed string literal
                                         System.out.println("Would you
                                                            ^
Blackjack.java:75: error: ';' expected
                                         System.out.println("Would you
                                                                       ^
Blackjack.java:76: error: ';' expected
like another card(y/n)?");
                 ^
Blackjack.java:76: error: not a statement
like another card(y/n)?");
                   ^
Blackjack.java:76: error: ';' expected
like another card(y/n)?");
                     ^
Blackjack.java:76: error: unclosed string literal
like another card(y/n)?");
                       ^
Blackjack.java:84: error: unclosed string literal
                                                 System.out.println("You
                                                                    ^
100 errors

1 个答案:

答案 0 :(得分:0)

Sorry everybody, but the issue ended up being related to me not correctly saving the file name on the ssh I'm using for the javac. Didn't mean to waste your time, and I appreciate the input. Will make sure to review much more closely in the future before bringing here.