Tuesday
October 21, 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:
Answer:

Related Questions

Computer Science - //program that puts two lists in order in one single list ...
Computers - //program that puts two lists in order in one single list with all ...
Java - I am supposed to convert a program i already made into a Java console ...
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 ...
Java - 1 public class testOperators 2 { 3 public static void main(String[] args...
Java - I need help putting the following trace into pseudocode 1 public class ...
Computer - on C++, I want to make an operation like " 2x + y - z ", I wrote ...
Computer Sciene-java - Write a loop that will continuously prompt the user for ...
computer science - int *reverse(const int *, int); int *temp; temp = reverse(...

Search
Members