First off, lets order your code using tab
public class Main { public static void main(String args[]) { int target = (int) (Math.random() * 1000); System.out.println("The number is " + target); } }
Now what you want to do is create an object of the class you say you need to use in school (Finder). Lets make the identifier for this object "obj".
public class Main { public static void main(String args[]) { Finder obj = new Finder(); int target = (int) (Math.random() * 1000); System.out.println("The number is " + target); } }
Now that we have done this you have to create a method in the class Finder that takes in an integer (so it can take in the variable you call target since it is an int itself). And example of a method like this that uses the variable target in a for-loop would be:
public void forLoopMethod(int target) { //Some sort of for loop involving the int target goes here: for() { } }
And then simply calling the method forLoopMethod in your class called Main
public class Main { public static void main(String args[]) { Finder obj = new Finder(); int target = (int) (Math.random() * 1000); obj.forLoopMethod(target); System.out.println("The number is " + target); } }