Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-14-2011, 08:31 PM   PM User | #1
crazins
New to the CF scene

 
Join Date: Sep 2011
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
crazins is an unknown quantity at this point
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;
  }
}
crazins is offline   Reply With Quote
Old 09-14-2011, 08:36 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Java != Javascript ... so can anybody move the topic?
devnull69 is offline   Reply With Quote
Old 09-14-2011, 08:38 PM   PM User | #3
crazins
New to the CF scene

 
Join Date: Sep 2011
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
crazins is an unknown quantity at this point
im sorry. i didnt realize i was in the wrong section...
crazins is offline   Reply With Quote
Old 09-14-2011, 08:49 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
crazins (09-14-2011)
Old 09-14-2011, 08:56 PM   PM User | #5
crazins
New to the CF scene

 
Join Date: Sep 2011
Posts: 8
Thanks: 2
Thanked 0 Times in 0 Posts
crazins is an unknown quantity at this point
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?
crazins is offline   Reply With Quote
Old 09-14-2011, 09:50 PM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-14-2011, 09:53 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
And the error message *told* you the problem. You just need to learn how to read error messages.
Quote:
"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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:12 AM.


Advertisement
Log in to turn off these ads.