Results 1 to 4 of 4
  1. #1
    thegross1 is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default number comparisson help

    I've been working on this for a while and can't get it to work. Basically it's a program that stores sale amounts into an array. Then asks the user to enter an amount, then prints the sales people who exceeded the amount. Here is my for loop.

    public void salesCompare()
    {
    for (int i=0; numCompare < this.sales[i]; i++)
    {
    System.out.println(this.sales[i]);

    }
    }//salesCompare()

    numCompare is the user entered number and sales[] is obviously my array. When I run it, nothing happens. Any suggestions?

  2. #2
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    7

    Default

    probably your numCompare is larger than sales[i];
    My IP address is 127.0.0.1

  3. #3
    thegross1 is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default

    Nope.
    I've been testing it with easy numbers. To test it I set sales[]=5.
    sales[0]=1
    sales[1]=2
    .
    .
    .
    sales[4]=5

    numCompare=2

    yet nothing prints

  4. #4
    thegross1 is offline Member
    Join Date
    May 2008
    Posts
    3
    Rep Power
    0

    Default

    Thanks for the response. I fixed by using the following:

    public void salesCompare()
    {
    for (int i = 0; i< sales.length; i++)
    {
    if (numValue < sales[i])
    System.out.println("Salesperson " +(i+1));
    }
    }//salesCompare()

Similar Threads

  1. how to use Scanner with a number
    By cew27 in forum New To Java
    Replies: 10
    Last Post: 04-03-2009, 06:23 PM
  2. line number
    By kazitula in forum New To Java
    Replies: 3
    Last Post: 11-21-2007, 10:27 PM
  3. Replies: 3
    Last Post: 11-18-2007, 07:41 PM
  4. how to know the number of bytes
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 05:13 PM
  5. how to know the number of the line
    By simon in forum New To Java
    Replies: 3
    Last Post: 08-01-2007, 04:59 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
  •