Declare and instantiate an array named scores of twenty-five elements of type int .
int scores = new int25;
Write a statement that declares an array named streetAddress that contains exactly eighty elements of type char .
char streetAddress = new char 80;
In a single statement : declare , create and initialize an array named a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20, …, 100 respectively.
int a = {10,20,30,40,50,60,70,80,90,100};
Declare an array named taxRates of five elements of type double and initialize the elements (starting with the first) to the values 0.10, 0.15, 0.21, 0.28, 0.31, respectively.
double taxRates = {0.10, 0.15, 0.21, 0.28, 0.31};
Write a statement to declare and initialize an array named denominations that contains exactly six elements of type of int .

Your declaration statement should initialize the elements of the array to the following values : 1, 5, 10, 25, 50, 100. (The value 1 goes into the first element , the value 100 to the last.)

int denominations = {1,5,10,25,50,100};
Declare an array reference variable , week, and initialize it to an array containing the strings “mon”, “tue”, “wed”, “thu”, “fri”, “sat”, “sun” (in that order).
String week = {“mon”, “tue”, “wed”, “thu”, “fri”, “sat”, “sun”};
Given an array a, write an expression that refers to the first element of the array .
a0
Given an array a, declared to contain 34 elements , write an expression that refers to the last element of the array .
a33
Assume that the array arr has been declared . Write a statement that assigns the next to last element of the array to the variable x, which has already been declared .
x=arrarr.length-2;
Given that the array monthSales of integers has already been declared and that its elements contain sales data for the 12 months of the year in order (i.e., January, February, etc.), write a statement that writes to standard output the element corresponding to October.

Do not write anything else out to standard output .

System.out.print(monthSales9);
System.out.println();
Given that an array named a with elements of type int has been declared , assign 3 to its first element .
a0 = 3;
Assume that an array named salarySteps whose elements are of type int and that has exactly five elements has already been declared .

Write a single statement to assign the value 30000 to the first element of this array .

salarySteps0 = 30000;
Assume that an array of integers named salarySteps that contains exactly five elements has been declared .

Write a statement that assigns the value 160000 to the last element of the array salarySteps.

salarySteps4 = 160000;
Assume that an array named a containing exactly 5 integers has been declared and initialized .

Write a single statement that adds 10 to the value stored in the first element of the array .

a0+= 10;
Given that an array of int s named a with 30 elements has been declared , assign 5 to its last element .
aa.length-1 = 5;
Given that an array named a whose elements are of type int has been declared , assign the value
-1
to the last element in a.
aa.length-1 = -1;
Assume that an array of int s named a has been declared with 12 elements . The integer variable k holds a value between 0 and 6. Assign 15 to the array element whose index is k.
ak = 15;
An array of int s named a has been declared with 12 elements . The integer variable k holds a value between 0 and 6. Assign 9 to the element just after ak.
ak+1 = 9;
An array of int s named a has been declared with 12 elements . The integer variable k holds a value between 2 and 8. Assign 22 to the element just before ak.
ak-1 = 22;
Assume that an array of integers named a has been declared and initialized . Write a single statement that assigns a new value to the first element of the array . The new value should be equal to twice the value stored in the last element of the array .
a0 = 2*aa.length-1;
Assume that an array of int s named a that contains exactly five elements has been declared and initialized . In addition, an int variable j has also been declared and initialized to a value somewhere between 0 and 3.

Write a single statement that assigns a new value to element of the array indexed by j. This new value should be equal to twice the value stored in the next element of the array (i.e. the element after the element indexed by j.

aj = 2 * aj+1 ;
Given an array arr, of type int , along with two int variables i and j, write some code that swaps the values of arri and arrj. Declare any additional variables as necessary.
int temp;
temp = arri;
arri = arrj;
arrj = temp;
Given an array of ints named x and an int variable named total that has already been declared , write some code that places the sum of all the elements of the array x into total. Declare any variables that you need.
total = 0;
for (int i=0; i<x.length; i++) total+=xi;
Given an array temps of double s, containing temperature data, compute the average temperature. Store the average in a variable called avgTemp. Besides temps and avgTemp, you may use only two other variables — an int variable k and a double variable named total, which have been declared .
for (total=0.0, k=0; k<temps.length; k++)
total += tempsk;
avgTemp = total/temps.length;
Given the integer variables x and y, write a fragment of code that assigns the larger of x and y to another integer variable max.
max = x;
if (y > max) max = y;
Write the definition of a method max that has three int parameters and returns the largest.
int max(int a, int b, int c) { return a<b? (b<c?c:b) : (a<c?c:a); }
An array of integers named parkingTickets has been declared and initialized to the number of parking tickets given out by the city police each day since the beginning of the current year. (Thus, the first element of the array contains the number of tickets given on January 1; the last element contains the number of tickets given today.)

A variable named mostTickets has been declared , along with a variable k.

Without using any additional variables , write some code that results in mostTickets containing the largest value found in parkingTickets.

mostTickets = parkingTickets0;
k = 1;
while (k<parkingTickets.length) {
if (mostTickets<parkingTicketsk)
mostTickets = parkingTicketsk;
k++;
}
Given an int variable k, an int array incompletes that has been declared and initialized, an int variable studentID that has been initialized , and an int variable numberOfIncompletes, write code that counts the number of times the value of studentID appears in incompletes and assigns this value to numberOfIncompletes.

You may use only k, incompletes, studentID, and numberOfIncompletes.

for (numberOfIncompletes=0,k=0; k<incompletes.length; k++)
if (incompletesk == studentID)
numberOfIncompletes++;
Write the definition of a method printArray, which has one parameter , an array of int s. The method does not return a value . The method prints out each element of the array , on a line by itself, in the order the elements appear in the array , and does not print anything else.
void printArray(int a) {
int i;
for (i=0;i<a.length;i++) {
System.out.print(ai);
System.out.println();
}
}
printArray is a method that accepts one argument , an array of int s. The method prints the contents of the array; it does not return a value. Inventory is an array of int s that has been already declared and filled with values .

Write a statement that prints the contents of the array inventory by calling the method printArray.

printArray(inventory);
Write the definition of a method named sumArray that has one parameter , an array of int s. The method returns the sum of the elements of the array as an int .
int sumArray(int a) {
int i,total=0;
for(i=0;i<a.length;i++)
total+=ai;
return total;
}
Write the definition of a method , isReverse, whose two parameters are arrays of integers of equal size. The method returns true if and only if one array is the reverse of the other. (“Reverse” here means same elements but in reverse order.)
boolean isReverse(int a, int b) {
int k;
for (k=0; k<a.length && ak==ba.length-1-k; k++);
return k==a.length;
}
Write a ‘main’ method that examines its command-line arguments and calls the (static ) method displayHelp if the only argument is the class name . Note that displayHelp accepts no parameters otherwise, ‘main’ calls the (static ) method argsError if the number of arguments is less than four. argsError accepts the number of arguments (an integer ) as its parameter otherwise, ‘main’ calls the (static ) method processArgs, which accepts the command-line argument array as its parameter .
public static void main(String args) {
if (args.length == 1)
displayHelp();
else if (args.length < 4)
argsError(args.length);
else
processArgs(args);
}
Given: an int variable k, an int array currentMembers that has been declared and initialized, an int variable memberID that has been initialized, and an boolean variable isAMember, 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!=currentMembersk; k++);
isAMember = k<currentMembers.length;
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 (zipcodeListk == zipcodeListk+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 (zipcodeListk == zipcodeListj)
duplicates = true;
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 (namesi == null || namesi.length() == 0)
hasEmpty = true;
Write the definition of a method , oddsMatchEvens, whose two parameters are arrays of integers of equal size. The size of each array is an even number. The method returns true if and only if the even-indexed elements of the first array equal the odd-indexed elements of the second, in sequence. That is if w is the first array and q the second array , w0 equals q1, and w2 equals q3, and so on.
boolean oddsMatchEvens(int a, int b) {
int k;
for (k=0; k<a.length && ak==bk+1; k+=2);
return k>=a.length;
}
x

Hi!
I'm Niki!

Would you like to get a custom essay? How about receiving a customized one?

Check it out