Last active
September 21, 2023 13:41
-
-
Save joeyv/7087747 to your computer and use it in GitHub Desktop.
Generates a random phone number
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.util.*; | |
public class Phone | |
{ | |
public static void main(String[] args) | |
{ | |
int num1, num2, num3; //3 numbers in area code | |
int set2, set3; //sequence 2 and 3 of the phone number | |
Random generator = new Random(); | |
//Area code number; Will not print 8 or 9 | |
num1 = generator.nextInt(7) + 1; //add 1 so there is no 0 to begin | |
num2 = generator.nextInt(8); //randomize to 8 becuase 0 counts as a number in the generator | |
num3 = generator.nextInt(8); | |
// Sequence two of phone number | |
// the plus 100 is so there will always be a 3 digit number | |
// randomize to 643 because 0 starts the first placement so if i randomized up to 642 it would only go up yo 641 plus 100 | |
// and i used 643 so when it adds 100 it will not succeed 742 | |
set2 = generator.nextInt(643) + 100; | |
//Sequence 3 of numebr | |
// add 1000 so there will always be 4 numbers | |
//8999 so it wont succed 9999 when the 1000 is added | |
set3 = generator.nextInt(8999) + 1000; | |
System.out.println ( "(" + num1 + "" + num2 + "" + num3 + ")" + "-" + set2 + "-" + set3 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thnx