April 16, 2014

Homework Help: Computer Science

Posted by Sarah on Tuesday, October 30, 2012 at 6:35pm.

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

Answer this Question

First Name:
School Subject:

Related Questions

Java Panel Problem - I am supose to draw a grid and center it with a 10 pix ...
computer science - Im trying to create an arraylist that's sorted but I have no ...
programming - m trying to create an arraylist that's sorted but I have no idea ...
Computer Science - Consider the following application files: /JavaCS1/src/...
Computer Sciene-java - Write a loop that will continuously prompt the user for ...
computer science - i have two numbers... 1564656 1981676 i want to check if the ...
Computer Science Computer Programming - Please help! I cannot figure out what I ...
shabou - Can someone please make a Binarytree of these methodes in Java?: public...
Computer Science Java - I have to write program for a dice game and use a ...
Java - 1 public class testOperators 2 { 3 public static void main(String[] args...