mercredi 23 décembre 2015

Questions about Random and Int (Java)

Assuming I generate a random number between 1-10, how do I use the random number generated into a for loop? Is there a way to convert random to int?

public class CityTravelerApp {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    // TODO code application logic here

    Queue myQueue= new Queue(80);

    //a. Generate a random number called num between 1 and 10, inclusive. 
    Random number = new Random();
    System.out.println(number.nextInt(10)+1);


    for(int i =1;i<=number;i++){
        System.out.println("Enter the name of country #" + i);
        String name = input.next();
    }


    }




Aucun commentaire:

Enregistrer un commentaire