Purchase Solution

Basic Arrays: Computer Science - Java Assistance

Not what you're looking for?

Ask Custom Question

Exercise 1 Array Basics
1.) Write array declarations for each of the following:
a. Eight grade point averages
a. Int gradePointAverage [] = new int [8];

b. Five first names
a. String firstName [] = new String [5];

c. 21 ages
a. Int ages [] = new int[21];

2.) Declare and initialize arrays that store the following:
a. The whole numbers 9, 36, 36, 54, and 65
i. Int numbers [] = {9, 36, 36, 54, 65};

b. The last names Smith, Johnson, and Hanson:
i. String lastNames [] = {"smith", "Johnson", "Hanson"};

c. The price 12.00, 101.00, and 3.50
i. Double price [] = {12.00, 101.00, 3.50};

3.) Write an assignment statement that assigns the value 999 to the first element of an array of integers named idNumbers.
Int idNumbers[];
idNumbers [0] = 999;

Exercise 2 Searching An Array for an Exact Match

String apples[] = {"Garla", "Rome", "Fuji", "Delicious"};
Int foundIt, i;
Final int MAX_APPLES = 4;
String inApple;
inApple = JOptionPane.showInputDialog("Enter apple type:");
for(I = 0; i <= MAX_APPLEs; i++)
{
If(inApple == apples[i])
{
foundIt = true;
}
}

1 . Is the for loop written correctly? If not, how can you fix it?

No it should be for(I = 0; i <=MAX_APPLEs; i++)

2. Which variable is the flag?

foundIt

3. Is the flag variable declared correctly? If not, what should you do to fix it?

No Boolean foundIt = false;

4. Is the comparison in the if statement done correctly? If not, how can you fix it?

inApple.equals(apples[i])

Purchase this Solution

Solution Summary

The solution contains the complete steps to arrive at the answer.

Solution Preview

Hi,

Based from your answers, most of them are good so that is nice.

Just a few corrections to be made:

=> Int and int are not the same and the correct ones should be int. Although this might be because of formatting, proper ...

Purchase this Solution


Free BrainMass Quizzes
Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Basic Networking Questions

This quiz consists of some basic networking questions.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.