471,873 Members | 1,683 Online

# creats and prints a random phone number

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 4025
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 2 posts views Thread by deko | 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 10 posts views Thread by Frinavale | last post: by reply views Thread by YellowAndGreen | last post: by 2 posts views Thread by beacampos | last post: by reply views Thread by isladogs | last post: by reply views Thread by beacampos | last post: by 8 posts views Thread by DJRhino1175 | last post: by reply views Thread by isladogs | last post: by 1 post views Thread by anoble1 | last post: by reply views Thread by beacampos | last post: by reply views Thread by jesuscortes0 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.