my assigment tell me to:

Write a program to randomly generate a 3-digit number N (it is ok if the number has
fewer than 3 digits). Create a number NN which is N placed next to it. Example, if
the number N is 263 then NN is 263263. If N is 7, NN is 007007. If N is 032, NN is
032032.
Next, divide NN by 7, and then by 11 and then 13.
Write the original number and the final result after the divisions.
Formula to randomly generate a 3-digit number is
(int)Math.floor(Math.random()*1000+1)

this is what I came up with but comes up with errors. Can I get some help

ublic class chapter3_problem_2 {

public static void main(String[] args) {
int n = (int)Math.floor(Math.random()*1000+1);
int nn = ("n" + "n");

System.out.println( +nn);

}
}

what am I doing wrong?

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by armsracer

Uhm, you are trying to assign a string an integer. I don't really know what happens, but that migt be the problem. Try defining a String strNN, and then assigning it n + n (careful so you don't evalauate n + n). Then you could define `int nn = Integer.parseInt(strNN)` Edit: Also, use

``````java.text.DecimalFormat threePlaces = new java.text.DecimalFormat("000");