Created
June 4, 2014 03:48
-
-
Save iagosousadev/76194064cdcbf0a58bd0 to your computer and use it in GitHub Desktop.
Código para criar numeros randomicos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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