# question about arrays; something simple

• January 31st, 2013, 09:38 AM
willc86
I am just curious what does int maxC = C[0]; mean. Why do I put C[0]; instead of int maxC = 0;

heres the code

public static void main...........

int []C = {2,4,543,2};
int maxC = C[0];
for (int i = 0; i<C.length;i++){
maxC = C[i];
}
• January 31st, 2013, 09:51 AM
KevinWorkman
Re: question about arrays; something simple
• January 31st, 2013, 09:58 AM
willc86
Re: question about arrays; something simple
ok I'll read that. if I have any questions ill let you know.
• January 31st, 2013, 09:59 AM
Norm
Re: question about arrays; something simple
Quote:

what does int maxC = C[0]; mean
int maxC <<< Defines an int variable named MaxC
= <<< assigns value to right to the variable on the left
C << name of an array
[0] << get the element at location 0 in the array
• January 31st, 2013, 10:23 AM
willc86
Re: question about arrays; something simple
so, int maxC = C[0] is initializing the first element in the array?
• January 31st, 2013, 10:30 AM
KevinWorkman
Re: question about arrays; something simple
No, it's initializing maxC to whatever is in the first element of the array. I suggest you step through your code with a debugger, or at least add some print statements, to make it more obvious what's going on in each step.
• January 31st, 2013, 10:48 AM
Norm
Re: question about arrays; something simple
• January 31st, 2013, 12:00 PM
willc86
Re: question about arrays; something simple
Quote:

Originally Posted by KevinWorkman
No, it's initializing maxC to whatever is in the first element of the array. I suggest you step through your code with a debugger, or at least add some print statements, to make it more obvious what's going on in each step.

yeah thats what I meant lol. I just wrote it quick without more details, but thats what I meant; that C[0] is ini. maxC to whatever the first element is in the array such as

int []A = {1,2,3,4,5};
maxA = A[0] --> it is starting off at 1 right?

and thanks for your help guys i appreciate it! I am just coding for fun right now!
• January 31st, 2013, 12:03 PM
KevinWorkman
Re: question about arrays; something simple
Quote:

Originally Posted by willc86
int []A = {1,2,3,4,5};
maxA = A[0] --> it is starting off at 1 right?

What happened when you tested that assumption with a print statement? :)
• January 31st, 2013, 02:13 PM
willc86
Re: question about arrays; something simple
well, when I printed it, it gave me the right answer I was looking for lol. It found the largest number I was looking for.
Do you guys know a good website with actual problems to practice? Like "create a method using an array to find the median of numbers, multiplying each blah blah. stuff like that
• February 1st, 2013, 08:19 AM
KevinWorkman
Re: question about arrays; something simple
You might want to check out Project Euler.