0

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
7 Years
Discussion Span
Last Post by armsracer
0

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

tags from now on please

I hope this helps on your homework!
Emil Olofsson

Edited by emilo35: n/a

0

You could use a java.text.DecimalFormat object to help format your integer into a string with 3 decimal places.

java.text.DecimalFormat threePlaces = new java.text.DecimalFormat("000");
strNN = threePlaces.Format(n) + threePlaces.Format(n);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.