# Computer Science

posted by
**Sarah**
.

public class RandomPhoneNumber

{

public static void main(String[] args)

{

int num1=(int)(Math.random()*7);

int num2=(int)(Math.random()*7);

int num3=(int)(Math.random()*7);

int set1=(int)(100+Math.random()*642);

int set2=(int)(1000+Math.random()*8000);

System.out.println("Your random phone number is: "+num1+""+num2+""+num3+"-"+set1+"-"+set2+"");

}

}

Hello. I had to create a program that generates a random phone number. I have to use math.random, the first three digits can't contain an 8 or 9, and the second set of three digits can't be greater than 742. Basically my logic in this is that num 1,2,&3 can go from 0 to 7. Set 1 can go from 100 to 742 (I put 642 b.c. 742-100 is 642 and I can only have 642 opitions), and finally the last four digits can range anywhere from 1000-9999 (same thing here, since 9999-1000 is 8999 that's the amount of choices I can have). I basically need to know if my logic in all this is correct and fits the guidelines. Since it is random there is really no way for me to tell. Thanks!!