lundi 19 octobre 2015

check if random number is equal to a specific number. java

Building a program that can check if a random number is = to a specific number. Here is what I have so far. I am generating a random number 10 times. And I want it to print out "The number (int var) was found (How ever many times it generated) times.". I keep running into problems such as trying to pull static variable from non-static variable. I'm not sure how to check if the integer is = to the random number.

import java.util.Random;
public class Driver{


    public static void main(String[] args)
    {

         Loop.loop4(4);
    }


public class Loop
{

    public static void loop4(int val)
    {

        for(int iteration = 1; iteration <=10; iteration ++)
        {
            Random number = new Random(); 
            number.nextInt(10);
        }

        System.out.println("The number " + val +" was found " (Dont know how to do this part);
    }


}




Aucun commentaire:

Enregistrer un commentaire