CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2011
    Posts
    2

    java code review?

    Hi

    I have some code segments. can someone please review it and tell me the problems if any?

    1.)
    String a=null;
    if (a!=null & a.length()>10) {
    System.out.println(“Inside if”);
    }
    System.out.println(“Outside if”);


    2.)
    int m = 0;
    while( m++ < 2 )
    System.out.println( m );
    3.)

    Hashtable hashtable = new Hashtable();
    hashtable.put("One", “1”);
    hashtable.put("Two", “2”);
    hashtable.put("One", “1”);

    while(hashtable.keys().hasMoreElements() ){
    System.out.println(hashtable.keys().nextElement());
    }

    Thanks for your time.

    Regards
    Arvind

  2. #2
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: java code review?

    Have you compiled and executed all the the code samples?
    What was the results?
    The compiler is very good at find syntax errors.
    Executing a program often finds logic errors.
    Norm

  3. #3
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: java code review?

    Given the code, this looks very much like a homework exercise.

    However, if you make some effort to review the code yourself, we'll tell you what we think of your review.

    It is easier to measure something than to understand what you have measured...
    Anon.
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  4. #4
    Join Date
    Jun 2011
    Posts
    35

    Re: java code review?

    Quote Originally Posted by dlorde View Post
    It is easier to measure something than to understand what you have measured...
    Anon.
    Love the quote!

    But yes, it appears to be a homework assignment. Why don't you just run it and see what it does. Then read through the code and try to understand how these results were produced? If you fail to do this last part, you can always come back and ask for help.

    Hope this helped,

    Laurent

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured