Write an application that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the output. Do not let the first three digits contain an 8 or 9 (but don’t be more restrictive than that), and make sure that the second set of three digits is not greater than 742. Hint: Think through the easiest way to construct the phone number. Each digit does not have to be determined separately.

Respuesta :

Answer:

Output;

Your random Phone number: 767-383-5743

Step-by-step explanation:

import java.util.Random;

class Main {

 public static void main(String[] args) {

   Random generator = new Random();

   

   int num1, num2, num3;

   num1 = ((generator.nextInt(7)+1) * 100) + (generator.nextInt(8) * 10) + (generator.nextInt(8

   ));

   num2 = generator.nextInt (643) + 100;

   num3 = generator.nextInt (9000) + 1000;

   System.out.println ("\n Phone number: " + num1 + "-" + num2+"-"+num3);

 }

}