Creating a random phone number in Java?

  • Thread starter Thread starter Ichiban_asakura
  • Start date Start date
I

Ichiban_asakura

Guest
I don't know what's wrong with the code:


public class untitled {

public static void main (String[] args){

int one, two, three, four, five;

one = (int)(Math.random() * 8 + 0);
two = (int)(Math.random() * 8 + 0);
three = (int)(Math.random() * 8 + 0);

four = (int)(Math.random() * 743 + 0);
if (four < 100 && four > 10)
four = ("0" + four);
if (four >= 9 && four <= 0)
four = ("00" + four);

five = (int)(Math.random() * 10000 + 0);
if (five >= 999 && five <= 100)
five = ("0" + five);
if (five >= 99 && five <= 10)
five = ("00" + five);
if (five >= 9 && five <= 0)
five = ("000" + five);

System.out.println(one + "" + two + "" + three + "-" + four + "-" + five);

}

}
 
Back
Top