Computer Science

posted by .

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

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. Java

    I am supposed to convert a program i already made into a Java console application that uses the Scanner class to read the user's input. This is the code i have that i need to convert. I don't know where to start. Here is the code import …
  2. Computer Science

    //program that puts two lists in order in one single list with all the numbers in order import java.util.Scanner; public class listOrder { public static void main (String [] args){ int [] list1; int [] list2; int [] list3; int temp; …
  3. Computers

    //program that puts two lists in order in one single list with all the numbers in order import java.util.Scanner; public class listOrder { public static void main (String [] args){ int [] list1; int [] list2; int [] list3; int temp; …
  4. computer science

    Im trying to create an arraylist that's sorted but I have no idea how to sort the numbers. I cant use the array.sort method here is my code: public class Testing { private int [] data; private int count; private static int defCapacity …
  5. programming

    m trying to create an arraylist that's sorted but I have no idea how to sort the numbers. I cant use the array.sort method here is my code: public class Testing { private int [] data; private int count; private static int defCapacity …
  6. Computer Science

    I posted this question before. The assignment was: write a Java method if the first parameter is less than the second parameter add the two and print the result ten times. How do I write the result 10 times as a loop?
  7. Computer Science

    How would I put this into one program? These are the directions: Write a method that takes two parameters. If the first parameter is equal to second parameter. Multiply both and print result. If the first parameter is less than the
  8. Computer Programming

    I already posted this question but I gave it a try I'm not sure if I'm on the right track: Make a util class with three methods. First method's name is add, that returns the result by adding two numbers. Second method's name is multiply, …
  9. Computer Science

    public class PrimeNumbers { public static void main(String[] args) { int x = 100; for(int i=2; i <= x; i++) { if(i%2==0) System.out.println("notprime"); System.out.println(i) ; if(i%1==1) System.out.println("prime"); } }
  10. Computer Science

    (From Lesson 17 of Blue Pelican Java) Use the following code for problems 1 – 15. In each problem state what’s printed. String s = “Lucky hockey puck”; String m = “uck”; int j = 6, z = 99; 1. int k = s.indexOf(m); System.out.println(k); …

More Similar Questions