-
-
Save soul0592/5899368 to your computer and use it in GitHub Desktop.
Generador de numeros pseudoaleatorios.
This file contains 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.*; | |
public class rand | |
{ | |
public static void main(String[] args) | |
{ | |
File a = new File("keyjv.dat"); | |
int largo = Integer.parseInt(args[0]); | |
int renglon = Integer.parseInt(args[1]); | |
int uno = 0, cero = 0,random; | |
try | |
{ | |
BufferedWriter bw = new BufferedWriter(new FileWriter(a)); | |
PrintWriter pw = new PrintWriter(bw); | |
for(int i = 0; i < renglon; i++) | |
{ | |
for(int j = 0; j < largo; j++) | |
{ | |
random = (int)(Math.random()*2); | |
pw.write(random + ""); | |
if(random == 1) | |
uno++; | |
else | |
cero++; | |
} | |
pw.write("\n"); | |
} | |
pw.write("Cero: "+cero+"\n"); | |
pw.write("Uno: "+uno+"\n"); | |
bw.close(); | |
pw.close(); | |
} | |
catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment