write code that assigns true to isAMember if the value of memberID can be found

Write code that assigns true to isamember if the

This preview shows page 9 - 13 out of 24 pages.

write code that assigns true to isAMember if the value of memberID can be found in currentMembers , and that assigns false to isAMember otherwise. Use only k , currentMembers , memberID , and isAMember . for (k=0; k<currentMembers.length && memberID!=currentMembers[k]; k++); isAMember = k<currentMembers.length;
Image of page 9
You are given an int variable k , an int array zipcodeList that has been declared and initialized, and an boolean variable duplicates . Write some code that assigns true to duplicates if there are two adjacent elements in the array that have the same value, and that assigns false to duplicates otherwise. Use only k , zipcodeList , and duplicates duplicates = false; for (k=0; !duplicates && k<zipcodeList.length-1; k++) if (zipcodeList[k] == zipcodeList[k+1]) duplicates = true; You are given two int variables j and k , an int array zipcodeList that has been declared and initialized, and an boolean variable duplicates . Write some code that assigns true to duplicates if any two elements in the array have the same value, and that assigns false to duplicates otherwise. Use only j , k , zipcodeList , and duplicates duplicates = false; for (j=0; !duplicates && j<zipcodeList.length-1; j++) for (k=j+1; !duplicates && k<zipcodeList.length; k++) if (zipcodeList[k] == zipcodeList[j]) duplicates = true;
Image of page 10
An array of Strings, names, has been declared and initialized. Write the statements needed to determine whether any of the the array elements are null or refer to the empty String. Set the variable hasEmpty to true if any elements are null or empty-- otherwise set it to false. hasEmpty = false; for (int i = 0; i < names.length; i++) if (names[i] == null || names[i].length() == 0) hasEmpty = true; 8.9 two dimensional arrays Declare a two-dimensional array of strings named chessboard. String [][] chessboard; Declare a two-dimensional array of integers named tictactoe. int [][] tictactoe; Declare and instantiate a 3x3 two-dimensional array of integers named tictactoe. int [][] tictactoe = new int[3][3] Assume that chessboard has been declared to be a two-dimensional array of strings. Write a statement that instantiates an 8x8 array of strings and assign it to chessboard. chessboard = new String[8][8]; Assume that tictactoe has been declared to be a two-dimensional array of integers. Write a statement that instantiates a 3x3 two-dimensional array of integers and assign it to tictactoe. tictactoe = new int[3][3]; Declare and create a two-dimensional array of chars, tictactoe, with 3 rows, each with 3 elements, and initialize it to all space characters. char[][] tictactoe = {{' ',' ',' '},{' ',' ',' '},{' ',' ',' '}}; Declare and create a two-dimensional array of ints, plan, with 2 rows, and initialize the first row to 8, 20, 50 and the second row to 12, 30, 75. int[][] plan = { {8,20,50}, {12,30,75} };
Image of page 11
A 2-dimensional 3x3 array of ints, has been created and assigned to tictactoe. Write an expression whose value is that of the first element in the first row.
Image of page 12
Image of page 13

You've reached the end of your free preview.

Want to read all 24 pages?

  • Spring '14
  • Array

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture