I am having trouble with any leading zeroes being printed,
also with ac1, ac2, ac3 showing as num1 (but not added together).
here is my code:
import java.util.Random;
public class phoneNumber
{
//---------------------------------------------------------
//This program will generate a random 10 digit phone number
//---------------------------------------------------------
public static void main(String[] args)
{
Random generator = new Random();
//integers ac1, ac2, ac3 = 3 number making up the area code
//num1 = Area Code, num2 = prefix, num3 = suffix
int ac1;
int ac2;
int ac3;
int num1;
int num2;
int num3;
ac1 = generator.nextInt(8);
ac2 = generator.nextInt(8);
ac3 = generator.nextInt(8);
num1 = (ac1 + ac2 + ac3);
{
if (num1 < 10)
num1 = (+00 + num1);
if (num1 < 100)
num1 = (+0 + num1);
}
num2 = generator.nextInt(743);
{
if (num2 < 100)
num2 = (+0+ num2);
if (num2 < 10)
num2 = (+00 + num2);
}
num3 = generator.nextInt(10000);
{
if (num3 < 1000)
num3 = (+0 + num3);
if (num3 <= 100);
num3 = (+00 + num3);
if (num3 <= 10);
num3 = (+000 + num3);
}
System.out.println("Your random phone number is " + num1 + "-" + num2 + "-" + num3);
}
}
example output:
Your random phone number is 5-88-3951
This post has been edited by macosxnerd101: 05 December 2010 - 01:31 PM
Reason for edit:: Please use code tags. Also, title renamed to be more descriptive. "Java Homework" describes 95% of the posts in this forum.

New Topic/Question
Reply




MultiQuote




|