Skip to content

Instantly share code, notes, and snippets.

@resetter
Last active August 29, 2015 14:01
Show Gist options
  • Save resetter/5d090f0527cdb79127c9 to your computer and use it in GitHub Desktop.
Save resetter/5d090f0527cdb79127c9 to your computer and use it in GitHub Desktop.
import java.io.PrintStream;
import java.io.IOException;
import java.io.File;
import java.util.Scanner;
import java.util.Random;
public class randInts
{ public static void main(String[] args)
{ try
{ PrintStream writer = new PrintStream( new File("randInts.txt"));
Scanner s = new Scanner(System.in);
System.out.print( "How many digits?: ");
int digits = s.nextInt();
Random rand = new Random();
for (int i = 0; i < digits; i++) {
int output = Math.abs((rand.nextInt(10)));
writer.print(output);
}
writer.close();
}
catch(IOException e)
{ System.out.println("An error occured while trying to write to the file");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment