Having problem with the output of a program


I having with the output of this program, The example of the output should be something like this.

Output Example: If the number N is 263 then NN is 263263. If N is 7, NN  should be 007007.

The Output I have now is ...The original number 0, the  final result after the divisions is 0. I need an ouput  as statement above in the example.

Here is what I have for my current program.

public class problemmagic
{
   public static void main(String[] args)
   {
   
   int n= (int)Math.floor(Math.random());
   int nn=n*1001;
   System.out.printf("The original number %3d, the the final result after the divisions %6d",n,nn/7/11/13);
   }
}


waltbaby315Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Randy DownsOWNERCommented:
Try printing out some of your variables (n, nn) in the intermediate steps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dave FordSoftware Developer / Database AdministratorCommented:

Since Math.random always returns a value between 0 and 1, then Math.floor of that value will always return zero, right?

HTH,
DaveSlash
0
Gary PattersonVP Technology / Senior Consultant Commented:
It is doing exactly what you coded it to do:

1) Math.random() returns a random DOUBLE value between 0 and 1.
2) Math.floor takes that random number and rounds it down the to nearest integer (Which will always be zero, since your random number is always less than 1).
3) (int) casts the resulting double into an integer, which will always contain 0.
4) Multiplying 0*1001 = 0

This feels like a homework assignment, so I'm going to let you figure out how to fix it.

- Gary


0
Suraj_MathewCommented:
public class problemmagic
{
   public static void main(String[] args)
   {

   int n= (int)Math.floor(Math.random());
   String value = String.valueOf(n);
   while(value.length() < 3) {
               value = "0" + value;
   }
   value = value + value;

   int nn = Integer.parseInt(value);

   System.out.printf("The original number %3d,\nString value of NN ->%s ,\nInteger value of NN-> %d, \nthe final result after the divisions %6d\n",n,value,nn,nn/7/11/13);
   }
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.