...

View Full Version : Really easy java program. can you help?



crazins
09-14-2011, 09:31 PM
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.


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;
}
}

devnull69
09-14-2011, 09:36 PM
Java != Javascript ... so can anybody move the topic?

crazins
09-14-2011, 09:38 PM
im sorry. i didnt realize i was in the wrong section...

Old Pedant
09-14-2011, 09:49 PM
int lowestNumber = find_sum(arrayA);

crazins
09-14-2011, 09:56 PM
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?

Old Pedant
09-14-2011, 10:50 PM
int small=999999999;

Right?

Old Pedant
09-14-2011, 10:53 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum