dimanche 21 mars 2021

Question on a program with date and random numbers

I am trying to create a program that generates random numbers. When the random number generated matches the current date it prints a counter for how many attempts it took. The date format is ddMMyyyy and the random numbers generated are 8 digits. At the end it prints the date and the count five times. This is what I have so far but it never returns an output.

import java.util.Random;
import java.util.Date;
import java.text.*;

public class Program1 {

public static void main(String[] args) {

Date date = new Date();
Random value = new Random();
int x = value.nextInt();

int counter = 0;

do {
    counter++;
} while(!date.equals(value));

if (date.equals(value)){
for(int i = 1; i < 6; i++) {
    SimpleDateFormat sdf = new SimpleDateFormat ("ddMMyyyy");
    System.out.println("The date is " + sdf.format(date) + "!");
    System.out.println("The Count is: " + counter);
    System.out.println();
}
}
}
}



Aucun commentaire:

Enregistrer un commentaire