//CS5-HMC-Sp.,00-HW3-5 //A. Khakpour, Feb., 00 class Phone2 { //----------------------------------------------------------------- // Produces a random phone number with various constraints. //----------------------------------------------------------------- public static void main (String[] args) { String result = ""; int resint =0; // none of the first three digits is higher than 7 result += (int) (Math.random() * 8); result += (int) (Math.random() * 8); result += (int) (Math.random() * 8); result += "-"; // then next set of digits cannot be greater than 742 resint = (int) (Math.random() * 743); if (resint < 10) result += "00"; else if (resint < 100) result += "0"; result += resint; result += "-"; resint = (int) (Math.random() * 10000); if (resint < 10) result += "000"; else if (resint < 100) result += "00"; else if (resint < 1000) result += "0"; result += resint; System.out.println ("A random phone number: " + result); } }