Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Really easy java program. can you help?

    Hi im trying to make a program that passes an array to a method. the method then finds the smallest number in the array and passes that number back to the main where its printed out. I am getting an error saying: "error: number cannot be resolved to a variable". I am using drjava. here is my code.

    Code:
    import java.util.*;
    
    public class homeWorkTwo{
      public static void main(String[] args)
      {
        int[] arrayA;
        arrayA = new int[10];
        arrayA[0]=7;
        arrayA[1]=5;
        arrayA[2]=8;
        arrayA[3]=9;
        arrayA[4]=2;
        arrayA[5]=10;
        arrayA[6]=11;
        arrayA[7]=1;
        int lowestNumber = find_sum(number);
        System.out.print("The smallest number is: "+lowestNumber);
      }
      public static int find_sum(int [ ] arrayB){
        int isItSmaller=0;
        int small=0;
        System.out.println("poop");
        for(int i=0;i<=7;i++){
          isItSmaller=arrayB[i];
          if(small<isItSmaller){}
          else
            small=isItSmaller;
        }
       System.out.print(small);
       return small;
      }
    }

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    Java != Javascript ... so can anybody move the topic?

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    im sorry. i didnt realize i was in the wrong section...

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    Code:
    int lowestNumber = find_sum(arrayA);
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    crazins (09-14-2011)

  • #5
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts
    omg your amazing! how the heck did u figure that out so quick?! i must really suck at programming lol. can you help me with one more thing? it only prints 0... based on what i have entered the lowest number is 1... any ideas?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    Code:
        int small=999999999;
    Right?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,441
    Thanks
    76
    Thanked 4,372 Times in 4,337 Posts
    And the error message *told* you the problem. You just need to learn how to read error messages.
    "error: number cannot be resolved to a variable".
    In other words, you don't have any variable that is named number. Okay, so then I look at your code and it's obvious what variable should be there, instead.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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