##### Help with Java: Single Dimensional Arrays

 Programming Tutor: None Selected Time limit: 1 Day

The project  is asking me to create a code using single dimensional arrays to compute the weekly hours for each employee (there are 8). So I have to gather the hours each employee has worked in one week. Then I have to get the sum of the hours worked

Feb 17th, 2015

You can declare a single-dimensional array of five integers as shown in the following example:

```int[] array = new int[5];
```

This array contains the elements from array[0] to array[4]. The new operator is used to create the array and initialize the array elements to their default values. In this example, all the array elements are initialized to zero.

An array that stores string elements can be declared in the same way. For example:

```string[] stringArray = new string[6];
```

## Array Initialization

It is possible to initialize an array upon declaration, in which case, the rank specifier is not needed because it is already supplied by the number of elements in the initialization list. For example:

```int[] array1 = new int[] { 1, 3, 5, 7, 9 };
```

A string array can be initialized in the same way. The following is a declaration of a string array where each array element is initialized by a name of a day:

```string[] weekDays = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
```

When you initialize an array upon declaration, you can use the following shortcuts:

```int[] array2 = { 1, 3, 5, 7, 9 };
string[] weekDays2 = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
```

It is possible to declare an array variable without initialization, but you must use the new operator when you assign an array to this variable. For example:

```int[] array3;
array3 = new int[] { 1, 3, 5, 7, 9 };   // OK
//array3 = {1, 3, 5, 7, 9};   // Error
```

C# 3.0 introduces implicitly typed arrays. For more information, see Implicitly Typed Arrays (C# Programming Guide).

Feb 17th, 2015

Cool Thanks Grady, do you mind helping me with another part real quick that i'm confused about? Now that I have my initialized for this problem, Im having trouble figuring out how to create a process that will take the hours the employees worked, adding them together to find the sum, then displaying them in descending order.

Feb 17th, 2015

yes i can..first best me in this and pay me something that i will appreciate. i will assist you till the end of you class

Feb 17th, 2015

Sure, Im pretty new to this site; how do i best you and how much do you think is a good amount for this question?

Feb 17th, 2015

\$20 is good for that question..just go to the site and select my answer as the best one and pay \$20. then you will  post the other one and i will also do for you. just do it now.  thank you

Feb 17th, 2015

...
Feb 17th, 2015
...
Feb 17th, 2015
May 23rd, 2017
check_circle