469,326 Members | 1,359 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,326 developers. It's quick & easy.

creats and prints a random phone number

1
The question is : 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. Hint: Think through the easiest way to construct the phone number. Each digit does not have to be determined separately.

I have done this so far lol :

import java.util.Random;

public class digits {

/**
* @param args
*/
public static void main(String[] args) {

int a;
Random s = new Random();

a = s.nextInt(30);

System.out.println(a);


// TODO Auto-generated method stub


}

}

So if any1 can help that would be great ...thanks.
Sep 4 '07 #1
2 3766
r035198x
13,262 8TB
The question is : 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. Hint: Think through the easiest way to construct the phone number. Each digit does not have to be determined separately.

I have done this so far lol :

import java.util.Random;

public class digits {

/**
* @param args
*/
public static void main(String[] args) {

int a;
Random s = new Random();

a = s.nextInt(30);

System.out.println(a);


// TODO Auto-generated method stub


}

}

So if any1 can help that would be great ...thanks.
1.) When posting any code please use code tags.
2.) You need to generate the numbers in sets (first three digits, middle three digits, and last four digits). This means you need to structure your program in a way that reflects that. You ccould even have three methods if you want. generateFirstThree, generateMiddleThree and generateLastFour.
Sep 5 '07 #2
Nepomuk
3,112 Expert 2GB
1.) When posting any code please use code tags.
2.) You need to generate the numbers in sets (first three digits, middle three digits, and last four digits). This means you need to structure your program in a way that reflects that. You ccould even have three methods if you want. generateFirstThree, generateMiddleThree and generateLastFour.
You could alternatively have one Function, that takes two values (max and min) and creates a random value, which lies between both.
Think about how you would use such a function to create a phone number, which fulfilles your needs.

Hint: What you've written until now, can be used in that function - but you'll have to find out how yourself. ^^
Sep 5 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by lharby | last post: by
7 posts views Thread by Jean-Francois.Doyon | last post: by
4 posts views Thread by darrel | last post: by
7 posts views Thread by laredotornado | last post: by
5 posts views Thread by lim4801 | last post: by
2 posts views Thread by =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post: by
7 posts views Thread by Propoflady | last post: by
Frinavale
10 posts views Thread by Frinavale | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.