1. What is an array? a set of data of the same type referenced with a common name

2. How many different variable types can the same array hold? one, ie a single array can’t hold name and numbers

3. Can an array hold strings? yes

4. Can the same array hold both the name of a student and their grades? no can’t mix them

5. Why are array convenient? they group together related data, they organize data, they assist in the sortingand searching of data

6. Give three examples where you might use arrays? grades, bus schedule, race times, wind data

7. List two advantages of using arrays to hold data. it’s easily manipulated, sorted easily, tallied easily, searched easily

8. How are arrays implemented? a. methods, b. classes, or c. objects as objects

9. How do you declare a one-dimensional array to hold ten characters? char sample[] = new char[10]

10. Even though will typically use one step to declare an array, the creation of an array is a two step process, what are the two steps? int sample[]; sample = new int[10]

11. What describes the position of an element within an array? index

12. If an array has 5 elements, what is the index value for the last item in the array? 4

13. Write a piece of code to initialize the five elements of a one-d array to the int value of 10.

for (int i=0; i<5; i++) sample[i] = 10;

14 How can you declare and initialize a one-d array called d with the values {2, 5, 7, 1, 10} using one line of code? int d[] = {2,5,7,1,10};

15. What would x = d.length give for the value of x? 5

16. Write a piece of code to initial an array called g that’s 2X3X2 to even numbers starting with zero.

n=0;

for (int d=0; d2; d++)

for (int c=0; c3; c++)

for (int r=0; r2; r++)

g[r][c][d] = n;

n = n + 2;

Example of hard coding numbers into an array

int[][][] = {

{ {0,12,4}, {4,16,5}, {8,20,6}},

{{2,14,7}, {6,18,8}, {10,22,9}}

};

16. What is at location g[1][2][0]?10 What about g[0][1][1]?16

17. Write a method to find the minimum value in a one dimensional array.

int min = 10000;

for (int i=0; i< 10; i++) if (sample[i] < min) min = sample[i];

18. What message do you get if you go beyond the index range of an array? index out of bounds

19. Explain what a Bubble sort is and how does it word? How many loop do you need?compares

values at two index locations and does a swap if necessary, it repeats this over and over, need two loops

20. What type of array would you use to hold all of your final exam grades (assume just 1st and 2nd semester) for all of your high school years. Write a piece of code to declare it. int g[][][] = new int[3][2][4]; this is a 3 dimensional array

21. What is an irregular array and give an example of declaring one called bus for a bus schedule that just runs M, W, F for 4 times each day, on Tues, Thurs, and Sat twice, and Sun once. an array that has a diff num of columns for each row int bus[][] = new int[7][];

bus[0] = new int[4]; //on Mondays you can hold 4 data pts

bus[1] = new int[2]; // on Tuesday, 2 data pts

bus[2] = new int[4]; and so on

22. If x = bus.length, and y = bus[0].length, z = bus[1].length, what are the values for x , y, and z? x =7, y = 4, z = 2

23. What type of an array would you use to hold the weight and height of students in the class of 2010? two dimension [22][2] in this case the row is the student number, if you had 22 in the class

24. What type of an array would you use to hold the hours you work each day for a part time job (assume you work diff numbers of hours each day)? irregular

25. Give an example of a need to use a 3-d array. height, weight, blood pressure

26. Suppose you have two arrays num1 and num2. What does num1 = num2 do? all values at the various positions of num1 match num2, you are causing num1 to reference num2

27. List two ways to search a data set linear, binary

28. Explain how a linear search works goes through item and compares

29. Explain how a binary search works starts with a sorted list and cuts in half over and over while making comparisons

30. Suppose you are thinking of a number from 0 to 100, what is the first number that it’s compared to? 50

31. Which way can be used if the data is unorganized? linear

32. Which search routine is faster for sorted data?binary

33. What single line of code can be used to declare a one D array called temp to hold 3 items? inttemp[] = new int[3];

34. How many loops are necessary in the Bubble sort routine? two

35. How many loops are necessary to find the largest number in an array? one

36. What kind of number is the index value for an array? Zero, or a positive integer

37. How many data points can array that’s 2x3x4 hold? 24

38. What is the term that describes the items that is used to access a value in an array?index

39. If you have two arrays, one called apple, and one orange, does this work: apple = orange:; Yes

40. What are strings in Java? objects, arrays, or characters? objects

41. List two ways to construct a string. String str = new String(“Hello”); String str = “Helllo”;

42. Create a string with the characters, “Hello” String str = “Helllo”;

43. Create a string that has no characters String empty = “”;

44. Can a string have just one character? Show an example String one = “A”; char one = ‘A’;

45. What does the following do, y = test.equals(“sup”), and what type of variable is y? return true if match, the variable y is boolean

46. Suppose the test is the string supal, what value does y have? false all the characters must match

47. Suppose data is the string “finish now” What does the following do, z = data.length(), ane what type is the variable z? z is an integer and in this case z = 10

48. Suppose data is the string “open now.” What does ch = data.charAt(8) return? returns the character .

49. What does ch = data.charAt(0) return? returns the o

50. Suppose data is the string “Broken” What is the value of x in the expression x = data.compareTo(“Summer”) ? x will be some negative number

51. If data = “Z”, what is the value of x in the expression x = data.compareTo(“B”) ? x = some positive number

52. Suppose data is the string “BrokenBroken” What is the value of x in the expression x =data.indexOf(“en”) ? x = 4 finds the first match

53. Suppose data is the string “BrokenBroken” What is the value of x in the expression x =data.lastIndexOf(“en”)? x = 10

54. Suppose data is the string “BrokenBroken” What is the value of x in the expression x =data.lastIndexOf(“on”)? x = -1 since it’s not found

55. Suppose data is the string “Broken” What is the value of part in the expression part =data.substring(3,6)? What type of variable is part? part would be a string and in this case ken

56. How can the contents of a string variable be altered? pg 196, string are immutable, contents can’t be altered

57. Create and fill an array with the strings “This”, “is” “great” String data[] = {“This”, “is”, “great”};

58. Create an appropriate array to hold the names and phone numbers of 3 people.

String numbers[][] = {

{“Tom”, “555-3322”},

{“Sam”, “555-8976”}.

{“Cole”, “596-2142”}

};

59. How can you search for a period in a sentence? y = sentence.indexOf(“.”), ch = sentence.charAt(“.”);

60. How can you tell if a character is capitalized? the decimal value is between 65 and 90 inclusive