Results 1 to 7 of 7
  1. #1
    swikar.java is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default Negative elements

    Anybody answer below question. please..


    Return number of negative elements in java.
    please write code including for loop.

    Thnaks,

  2. #2
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    Are the elements in an array, arraylist, linked list, etc.? You need to provide more information...

  3. #3
    swikar.java is offline Member
    Join Date
    Oct 2008
    Posts
    7
    Rep Power
    0

    Default

    This is only sequence.
    Doesn't mater array or arraylist.
    I want just return negative eliments.

  4. #4
    matzahboy is offline Member
    Join Date
    Nov 2008
    Posts
    67
    Rep Power
    0

    Default

    I don't understand what you are asking... Sorry

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by swikar.java View Post
    Anybody answer below question. please..


    Return number of negative elements in java.
    please write code including for loop.

    Thnaks,
    Yes, what type of variable you want to return. It's possibly to return any primitive variables as negative values.

    Java Code:
    return -23;
    But you should provide more clear details that what you want to do.

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default Guessing...

    Let's see if I can help figure this out, becasue I'm not even sure the OP knows what he/she wants.
    Return number of negative elements in java.
    This is only sequence.
    Doesn't mater array or arraylist.
    From this I assume the following:
    • From a list (doesn't matter in what format) the OP has to return the number of negative elements.


    please write code including for loop.
    • The code must contain a "for" loop.


    With those requirements, I would think the following would be enough:

    • Create list of numbers that contain some negative numbers. I would suggest an array.
    • Using a "for" loop to go through the array, compare each array element if it's a negative number (using an "if" statement).
    • If yes, then increment the counter and continue with the comparation.
    • If not, just continue with comparation.
  7. Print the amount of negative numbers found in the array


  8. swika: It's this what you need to do?

    Luck,
    CJSL
Chris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Reply With Quote Reply With Quote

  • #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  • Similar Threads

    1. [SOLVED] Array of first negative number
      By random0munky in forum New To Java
      Replies: 9
      Last Post: 12-08-2008, 11:17 PM
    2. Missing Elements
      By princess in forum NetBeans
      Replies: 1
      Last Post: 10-29-2008, 11:51 PM
    3. deleting elements
      By nalinda in forum New To Java
      Replies: 2
      Last Post: 12-06-2007, 01:42 AM
    4. Help with array of elements
      By zoe in forum New To Java
      Replies: 1
      Last Post: 07-24-2007, 05:33 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
    •