I am going through a Lewis and Loftus book doing all of the examples, trying to get myself reacquainted with the Java language. I've included the exercise's requirements inside of the [CODE] tags.
I've tried everything from a BUNCH of if statements, to trying to make up the 'area' variable out of three separate characters, but I cannot seem to get it right. How do I go about limiting the output so that there are no 8 or 9s?
import java.util.Random; /* 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.*/ class Test { public static void phoneNumber(){ Random random = new Random(); int area = random.nextInt(900)+100; int mid = random.nextInt(643)+100; int last = random.nextInt(9000)+1000; System.out.println(area+"-"+mid+"-"+last); } public static void main(String[] args){ phoneNumber(); } }