Hey every I'm stuck with trying to generate 1000 random numbers that have 7 digits my code is here below
I don't know how to set it to a fix digit number, I know it's simple but it's doing my head in
can anyone help me? thanks
I want numbers between 0000001 - 9999999 if possible with a character at the end
Ok the output is in a txt file
Random PPS Number : 1911462N
Random PPS Number : 2714102K
Random PPS Number : 5070317E
Random PPS Number : 8030837K
Random PPS Number : 4358369S
Random PPS Number : 5350002N
but my problem is I don't know how to sort it in lexicographical order
Grot
import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Random; public class Assignment_Part2{ /** * @param args */ private static PrintWriter outputStream; public static void main(String[] args) { String fileName = "pps.txt";//input the data to a file named text.txt try {//using the try catch operator outputStream = new PrintWriter(fileName);// using the printwriter method to insert data to the file Random r = new Random(); String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (int i = 0; i < 1; i++) { } // prints random characters from alphabet for (int j = 1; j <= 1000; j++){// using a for loop to gernerate numbers from 9999999 - 1000000 int myInt = 1000000 + (int)(Math.random() * ((9999999 - 1000000) + 1)); outputStream.println("Random PPS Number : " + myInt + alphabet.charAt(r.nextInt(alphabet.length())) + " ");//output stream to print the numbers to the pps.txt file } // stores in Ram First outputStream.close(); // flushes the data to the file System.out.println("PPS Numbers Are Printed Out In A Text File");//outputs to the user that it's done } catch (FileNotFoundException e) {// the catch operator is used to give the user an error System.out.println("File Not Found");//outputs this if an error is found } } }