Basically, i need to use the value of spaces from this method spacesCount in another method, or in the main void run. But it won\'t let me use outside?
You are providing the value of spaces as the return value from the method. So you need to store the result in a variable and use it in your other method:
public static void main(String args[]) {
String myString = "this is a test";
int spaces = spacesCount(myString);
// use spaces to do something
}