Arrays Flashcards
What is the primary purpose of using arrays in Java?
a) To store values of different data types
b) To store multiple indexed values of the same data type
c) To handle database queries
d) To format strings
b) To store multiple indexed values of the same data type
Which Java method splits a string into an array of substrings based on a specified delimiter?
a) split()
b) join()
c) parse()
d) substring()
a) split()
What type of array is ‘args’ in the main() method?
a) Integer array
b) Float array
c) String array
d) Boolean array
c) String array
How can arguments be passed to a Java program?
a) Only from the command line
b) Only from an IDE
c) From both the command line and an IDE
d) They cannot be passed
c) From both the command line and an IDE
What method is used to access the length of an array in Java?
a) size()
b) getLength()
c) length()
d) arrayLength()
c) length()
In a two-dimensional array, what does the first index represent?
a) The row
b) The column
c) The length
d) The width
a) The row
What does the ‘args.length’ expression return?
a) The number of characters in the first argument
b) The number of arguments passed to the program
c) The size of the first argument
d) The total length of all arguments
b) The number of arguments passed to the program
In the grid example, which character represents ‘Byorki - Ranger’?
a) K
b) A
c) T
d) B
d) B
What is the purpose of the movePlayer method?
a) To move a player to a new location on the grid
b) To delete a player from the grid
c) To print the player’s current location
d) To initialize the game grid
a) To move a player to a new location on the grid
In the movePlayer method, what does ‘newY++’ do when the direction is ‘N’?
a) Moves the player south
b) Moves the player east
c) Moves the player west
d) Moves the player north
d) Moves the player north