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];
}
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
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];
}
Recommended reading: Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
ok I'll read that. if I have any questions ill let you know.
int maxC <<< Defines an int variable named MaxCwhat does int maxC = C[0]; mean
= <<< 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
If you don't understand my answer, don't ignore it, ask a question.
so, int maxC = C[0] is initializing the first element in the array?
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.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
See the description of an assignment statement:
Assignment, Arithmetic, and Unary Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
If you don't understand my answer, don't ignore it, ask a question.
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!
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
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
You might want to check out Project Euler.
Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!