And truth be told I really have no clue what to do except
can anyone give me any insight..? I've no idea where to place it or what else to do.boolean[] deck = new boolean[52];
Guess you wanna know how to use an array. Here is a crash course:
1.Declare and define an array:
type var_name[] = new type[array_size] ;
Where type could be a basic type (like int, boolean...) or a user defined type (like Poker)
2.Access a member of array which is located at index/position N:
Use the subscript operator (i.e. "[]" ) like this var_name[N].
System.out.println( "Nth element = " + String.valueOf(var_name[N]) ) ;
/*PS: valueOf() is overloaded for basic types only, won't work for user-defined types*/
To assign a value:
var_name[N] = new type() ;
3.Loop thru an array: array_variable_name.length gives you the length of an array.
for( int i = 0; i < var_name.length; i++ )
System.out.println( String.valueOf( var_name[i] ) ) ;
Here is a full example:
public class test {
public static void main( String[] args ) {
//declare and define
boolean arr[] = new boolean[10] ;
//init
for( int i = 0; i < arr.length; i++ )
arr[i] = false ;
//access an element
arr[(int) (Math.random() * 10)] = true ;
//print the contents
for( int i = 0; i < arr.length; i++ )
System.out.println( String.valueOf( arr[i] ) ) ;
}
} thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75