Programming project. blackjack, String array issue

Click For Summary
SUMMARY

The discussion centers on a programming issue in a Blackjack class written in Java. The error arises from a missing comma in the String array declaration for suits, specifically between "Spades" and "Clubs". This syntax error leads to multiple compilation errors when the line is included. Correcting the array declaration resolves the issue, allowing the program to compile successfully.

PREREQUISITES
  • Java programming fundamentals
  • Understanding of arrays in Java
  • Basic knowledge of syntax errors and debugging
  • Familiarity with the Random class in Java
NEXT STEPS
  • Review Java array syntax and common pitfalls
  • Explore Java debugging techniques for identifying syntax errors
  • Learn about the Random class and its applications in Java
  • Study best practices for writing and organizing Java classes
USEFUL FOR

Java developers, programming students, and anyone interested in improving their debugging skills in Java applications.

opaquin
Messages
10
Reaction score
0
Not sure what's going one, as soon as I remove the line with String[] arraySuit... all errors go away. With that statement in I get errors on several lines. Cannot figure out what's wrong.

Code:
/*
 * Semester Project
 * Blackjack Class
 */
package project;
import java.util.*;

/**
 * Oliver Paquin
 * CIS132
 * December 10, 2012
 */

class Blackjack 
{
    //declare and set arrays for suits and cards
    String[] arraySuit = {"Hearts", "Diamonds", "Spades" "Clubs"};
    int[] arrayCards = {1,2,3,4,5,6,7,8,9,10,11,12,13};
    
    
    int number1, number2;
    
    public int dealCards()
    {
        //Create Random class object
        Random randomNumbers = new Random();
        
        number1 = randomNumbers.nextInt(3);
        number2 = randomNumbers.nextInt(12);  
        
                 
        //Display random numbers for testing
        
        System.out.println(arrayCards[number2]);
        
        return number1;
        
    }
    
}
 
Physics news on Phys.org
Could it be because you're missing a comma between "Spades" and "Clubs"?

(Since "Spades" and "Clubs" are separate strings in the array, they need to be separated by a comma.)
 
Thanks...tomorrow I'm going to get my eyes checked.
 

Similar threads

  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 12 ·
Replies
12
Views
4K