mercredi 4 novembre 2015

Java: Number Generator Compared to todays Date

Can anyone help me get this code to run, it currently compiles but no output, the code is supposed to generate a random 8 digit number, and then compare it to todays date, if they both match output certain code other wise just post the number

import java.util.*;
import java.text.*;

public class RandomNumber {

    public static void main(String[] args) {
    }

    public static void generateMyNumber() {
        //Date dNow = new Date( ); // Instantiate a Date object
        int dNow = (int) new Date().getTime();
        SimpleDateFormat ft
                        = new SimpleDateFormat("MMddyyyy");
        int aNumber = (int) (Math.random() * 90000000) + 10000000;
        String val = "" + aNumber;
        if (dNow == aNumber) { //compare date to number generated
            System.out.println("It is your lucky day"); //print first line if the numbers match
            System.out.println("The count is: " + aNumber);
        } else
            System.out.println((aNumber));
    }
}




Aucun commentaire:

Enregistrer un commentaire