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!!

Based on your code, your logic seems to be correct and it follows the given guidelines for generating a random phone number. Let's break down your code to understand the logic and ensure it meets the requirements:

1. You declared three variables: num1, num2, and num3, which will generate the first three digits of the phone number. By using `(int)(Math.random()*7)`, you are multiplying the random number generated by `Math.random()` (which is between 0 and 1) by 7 to get a number between 0 and 6. This ensures that the first three digits don't contain 8 or 9.

2. You declared two variables: set1 and set2, which will generate the second set of three digits and the last four digits of the phone number, respectively. For set1, you used `(int)(100+Math.random()*642)`. By adding 100 to the random number between 0 and 1 multiplied by 642, you ensure that set1 will be between 100 and 742, fulfilling the requirement. Similarly, for set2, you used `(int)(1000+Math.random()*8000)`, which will generate a number between 1000 and 8999.

3. Finally, you printed the generated phone number using `System.out.println("Your random phone number is: "+num1+""+num2+""+num3+"-"+set1+"-"+set2+"");`. The output will be the concatenation of the randomly generated digits and sets.

Based on this analysis, your code appears to be correctly generating random phone numbers that follow the given guidelines.

yes i think