java question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shirsa
    New Member
    • Mar 2008
    • 8

    java question

    what is the correct answer of thes question....

    public class par
    {

    public static void main (String[] args)
    {
    int i=0;
    addtwo(i++)
    system.out.prin tln(i);
    }
    static void addtwo(int i)
    {
    i+=2;
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by shirsa
    what is the correct answer of thes question....
    What do *you* think the answer is? We are not an answering service; please
    try to think about those questions yourself.

    kind regards,

    Jos (mod)

    ps. read the forum quidelines (see the 'Help' link near the top of this page)

    Comment

    • shirsa
      New Member
      • Mar 2008
      • 8

      #3
      Originally posted by JosAH
      What do *you* think the answer is? We are not an answering service; please
      try to think about those questions yourself.

      kind regards,

      Jos (mod)

      ps. read the forum quidelines (see the 'Help' link near the top of this page)
      then plz change the title of the site
      "Java Forum
      Java programming help. Post your Java questions in this forum. "

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by shirsa
        then plz change the title of the site
        "Java Forum
        Java programming help. Post your Java questions in this forum. "
        No, *you* program your Java programs and we can help you with it; we don't
        just supply answers to arbitrary questions so you can just copy and paste
        them and turn them in as if they were your intellectual work.

        kind regards,

        Jos (mod)

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by shirsa
          then plz change the title of the site
          "Java Forum
          Java programming help. Post your Java questions in this forum. "
          There's no need to change the title it's still valid.
          You can post your Java questions here but you must post them according to the posting guidelines

          Comment

          • shirsa
            New Member
            • Mar 2008
            • 8

            #6
            then tell me that whether i'm right or wrong
            the ans is 2

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by shirsa
              then tell me that whether i'm right or wrong
              the ans is 2
              Hopefully you are not demanding answers because experts here give their help free of charge. It is only fair that you be polite to them as well.
              How did you come up with the answer 2? By the answer do you mean the output?

              P.S You can check on a compiler whether you are right or wrong.

              Comment

              • shirsa
                New Member
                • Mar 2008
                • 8

                #8
                Originally posted by r035198x
                Hopefully you are not demanding answers because experts here give their help free of charge. It is only fair that you be polite to them as well.
                How did you come up with the answer 2? By the answer do you mean the output?

                P.S You can check on a compiler whether you are right or wrong.

                as i++ return the value before increment...so "static void addtwo " this function will give the ans 0+2=2 .....
                is it right?

                i have not the compiler so i'm asking....ok then goodbye

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by shirsa
                  as i++ return the value before increment...so "static void addtwo " this function will give the ans 0+2=2 .....
                  is it right?

                  i have not the compiler so i'm asking....ok then goodbye
                  But that i that is incremented by two is not the same as the i that is printed in your main (your println statement needs an uppercase S for system BTW).

                  Comment

                  • shirsa
                    New Member
                    • Mar 2008
                    • 8

                    #10
                    Originally posted by r035198x
                    But that i that is incremented by two is not the same as the i that is printed in your main (your println statement needs an uppercase S for system BTW).
                    ok thanks....i got it...thank you very much....

                    Comment

                    • shirsa
                      New Member
                      • Mar 2008
                      • 8

                      #11
                      now i've another question may i ask u?

                      Comment

                      • r035198x
                        MVP
                        • Sep 2006
                        • 13225

                        #12
                        Originally posted by shirsa
                        now i've another question may i ask u?
                        As long as you stick to the posting guidelines you can go ahead and ask.
                        If it's a different question you'll want to start another thread for it and give it a title that is problem specific. Then you'll need to explain what you have tried as well.

                        Comment

                        • shirsa
                          New Member
                          • Mar 2008
                          • 8

                          #13
                          in java
                          x[0]++,
                          is it legal??

                          Comment

                          • pralu
                            New Member
                            • Mar 2008
                            • 34

                            #14
                            the answer to ur question is 1.... its not 2

                            Comment

                            • r035198x
                              MVP
                              • Sep 2006
                              • 13225

                              #15
                              Originally posted by shirsa
                              in java
                              x[0]++,
                              is it legal??
                              Read my reply above again.
                              Also download and read the Java tutorial from Sun. There's no point in trying to answer Java questions before about the Java language itself. You'll be able to answer all of those questions yourself after reading the relevant parts of that tutorial.

                              Comment

                              Working...