Results 1 to 10 of 10
Like Tree1Likes
  • 1 Post By Tolls

Thread: Java Code

  1. #1
    Rubel Rana is offline Member
    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

    Thumbs up Java Code

    Java Code:
    public class a {
        public static void main(String[] args) {
            int[] test = new int[2];
            test[0] = test[1] = 5; 
            System.out.println(test[0] + "," + test[1]);
            fiddle(test, test[1]);
            System.out.println(test[0] + "," + test[1]);
        }
        static void fiddle(int[] test, int element) {
            test[0] = 10;
            test[1] = 11;
            element = 12;
            System.out.println(test[0] + "," + test[1] + "," + element);
            test = new int[2];
            test[0] = 20;
            test[1] = 21;
            System.out.println(test[0] + "," + test[1]);
        }
    }
    Output:
    5,5
    10,11,12
    20,21
    10,11

    Ques:in line number 15,16 i initialized with 20,21,why again they print previous initialization,10,11?
    Last edited by Rubel Rana; 08-08-2013 at 01:56 PM.

  2. #2
    Teedo is offline Member
    Join Date
    Apr 2012
    Posts
    61
    Rep Power
    0

    Default Re: Java Code

    nevermind :)
    Last edited by Teedo; 08-08-2013 at 03:12 PM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Java Code

    Rubel Rana, I have already advised you to read the Forum Rules: Java Code

    If you continue to ignore the rules, your threads may be removed and you may be banned for a period.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Java Code

    Teedo's not quite correct.
    Up until line 14 the 'test' parameter is referencing the same object as the 'test' variable in main().
    On line 14 you make the 'test' parameter (which is local to the method) point at a different object.
    The 'test' in main(), however, is still pointing at the original one.
    Rubel Rana likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    Rubel Rana is offline Member
    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

    Default Re: Java Code

    If you look that i changed lot than before i asked question,bt specially whts my wrong here now? I really cant understand and i being tired getting your objection

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,820
    Rep Power
    19

    Default Re: Java Code

    I'm assuming that's in reply to Darryl?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,712
    Rep Power
    5

    Default Re: Java Code

    "java code" is hardly a title that describes your problem, don't you think? We all know its going to be Java code, this is a Java forum after all.

    You were advised to read the rules. I quote:

    Use a Title that Describes the Content of Your Post <-- well you didn't do that

    When asking for assistance on a particular topic, please use a descriptive subject to illustrate your situation. Please avoid the following generic examples:

    "Help Please!" or "Need Help! or "Little Help" <-- oops, you did exactly this

    Instead, be descriptive and concise. <-- well you are concise, but not descriptive
    In the future, try to pick a subject that honestly explains what you want to achieve. Whether you agree or disagree with this forum rule is besides the point. They're the rules and we should follow them, if we don't want to we should go somewhere else.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    Rubel Rana is offline Member
    Join Date
    Jul 2013
    Posts
    14
    Rep Power
    0

    Default Re: Java Code

    Thanx,In this post,i have just title problem?

  9. #9
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,712
    Rep Power
    5

    Default Re: Java Code

    Perhaps there were more infractions at the time that DB posted, since I see you edited your first post. At this point: who cares, its in the past.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  10. #10
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,411
    Rep Power
    5

    Default Re: Java Code

    I'll take your word for it since Teedo edited the post.

    Regards,
    Jim
    The Java Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Compiling another java code from our code
    By madhav.dubey9 in forum New To Java
    Replies: 18
    Last Post: 03-11-2013, 04:54 PM
  2. Replies: 16
    Last Post: 01-31-2012, 08:36 PM
  3. Replies: 0
    Last Post: 02-21-2011, 11:50 AM
  4. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 11:14 AM
  5. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •