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.

Results 1 to 11 of 11

Thread: question about arrays; something simple

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default question about arrays; something simple

    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];
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: question about arrays; something simple

    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!

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: question about arrays; something simple

    ok I'll read that. if I have any questions ill let you know.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: question about arrays; something simple

    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
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: question about arrays; something simple

    so, int maxC = C[0] is initializing the first element in the array?

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    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!

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: question about arrays; something simple

    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: question about arrays; something simple

    Quote Originally Posted by KevinWorkman View Post
    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!

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: question about arrays; something simple

    Quote Originally Posted by willc86 View Post
    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?
    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!

  10. #10
    Junior Member
    Join Date
    Nov 2012
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  11. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: question about arrays; something simple

    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!

Similar Threads

  1. Simple Question - How to Parse a CSV File Into Different Data Type Arrays?
    By Obiwan64 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 26th, 2012, 07:30 PM
  2. Question regarding 2d arrays
    By Demetrius82 in forum Java Theory & Questions
    Replies: 8
    Last Post: May 30th, 2011, 04:06 PM
  3. Question on arrays.
    By SV25 in forum Java Theory & Questions
    Replies: 4
    Last Post: April 24th, 2011, 02:45 AM
  4. help with homework - simple arrays
    By sensoryctascale in forum Java Theory & Questions
    Replies: 3
    Last Post: April 5th, 2011, 01:39 AM
  5. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 03:47 AM