@Mephisto:No he does not.nevermind
Also, 3man75, good grief, you NEVER need to import Object.
I want to help with this, but I'd end up completely rewriting your code and not really helping.
Also, you really, really, really need to learn more about how to write readable variable names...AND STOP MAKING MULTIPLE SCANNERS POINTED AT SYSTEM.IN FOR LIKE THE TENTH OR SO TIME AAAUGH. Sorry. I shouldn't shout. But you only need the one Scanner, let's call it input, and then you can call input.nextInt() multiple times.
...Also, screaming about THIS METHOD IS BEING CALLED BY MAIN! is...Not a guaranteed truth, in addition to being really weird documentation-wise, because the line of code you wrote ISN'T being called in main, it's being called in your method. One's code should not depend on being called by certain other code unless it's a private method, which I will not talk about because that's outside your current scope.
...Sod it, I'm going to write an unconnected example in the hopes that it actually gets through.
import java.util.Scanner;
public class Demo{
Scanner scan = new Scanner(System.in); //And notice how there is ONE Scanner, not two or three.
public static void main(String[] args){
//I'll avoid complicating things and just write it to go through each method once, though simply wrapping this with a while loop and implementing some sort of menu shouldn't be hard.
System.out.println("Input the initial value for instancevariable");
DemoObject whatdoesitdo = new DemoObject(scan.nextInt()); //Much less code to write than creating a new variable to store a value you only use once.
//Now, to demonstrate proper object-based I/O.
System.out.println("Called singleUseThing and got "+whatdoesitdo.singleUseThing()); //This is what a return statement is for. It hands data back to the method that called things.
System.out.println("How many times would you like to call multiUseThing?");
int[] output; //Have to declare this outside of the loop so it doesn't vanish after the first iteration.
for(int count = 0, int max = scan.nextInt() /*Reusing a Scanner, see? Also, you can do this comma thing here.*/, output = whatdoesitdo.multiUseThing(max); count<max; count++){
System.out.println("Result "+(count+1)+" of multiUseThing was "+output[count]);
}
}
}
public class DemoObject{
int instancevariable;
Random RNGesus = new Random();
DemoObject(int setup_value){
instancevariable=setup_value;
}
public void setInstanceVariable(int to_set){
instancevariable = to_set;
}
public int singleUseThing(){
return RNGesus.nextInt()*instancevariable;
}
public int[] multiUseThing(int num_times){
int[] temp_storage = new int[num_times];
for(int count = 0; count<num_times; count++){
temp_storage[count] = RNGesus.nextInt()*instancevariable;
}
return temp_storage; //Handing the array back for whatever. If you only wanted to print odd-numbered results, you could do that without mucking up the object for uses that need all the results printed.
}
I apologize for the tabs, but it was much faster than spaces, especially because I typed this on my phone