Skip to content

Instantly share code, notes, and snippets.

@iagosousadev
Created June 4, 2014 03:48
Show Gist options
  • Save iagosousadev/76194064cdcbf0a58bd0 to your computer and use it in GitHub Desktop.
Save iagosousadev/76194064cdcbf0a58bd0 to your computer and use it in GitHub Desktop.
Código para criar numeros randomicos
import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.Random;
public class RndNumbers {
public static void main (String[] args) throws IOException{
Scanner scan = new Scanner(System.in);
Random rndnum = new Random();
System.out.print("Quantos numeros voce deseja? ");
int n = scan.nextInt();
System.out.print("Qual o numero maximo? ");
int s = scan.nextInt();
scan.close();
File file = new File("rndnumbers.txt");
if (!file.exists()) {
file.createNewFile();
}
BufferedWriter bw = new BufferedWriter(new FileWriter(file.getAbsoluteFile()));
for (int i = 1; i <= n; i++) {
Integer num = rndnum.nextInt(s);
bw.write(num.toString() + " ");
}
bw.close();
System.out.print("Terminado!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment