lundi 26 novembre 2018

Increments with random numbers

I have been trying to get this script to work for quite a while now. I usually have no problem with increments but I can't seem to get the architecture down for this one. Here is what I have so far.

package Temper;
import java.util.Random;
 import java.util.Scanner;
 public class Temp {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    {
    System.out.println("I am going to store a bunch of random numbers so pick the first one ");
    Scanner in = new Scanner(System.in);
    in.nextInt();
    }
    {
        System.out.println("I know I said pick a number of your own but here are a bunch of random ones instead \n");
    {
            method1();
        }
        }
        }
    public static int method1()
        {   
            int rv = 0;
            for(int i = 0; i <= 99; i++);
            {

                Random r = new Random();
                int number = r.nextInt(100) + 1;
                System.out.println(number);
                rv = rv + number;
            }
            return rv;
        }   
 }              

When I run the script in the console it ust gives me one number instead of 100. Any help figuring this out would be much appreciated. Thank You




Aucun commentaire:

Enregistrer un commentaire