• Post Reply Bookmark Topic Watch Topic
  • New Topic

Issue faced while run-time of a program  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was writing a program on BlueJ which would separate the integer part and real part of a floating point number on separate lines.An example could be:
for float n=25.7657
Output:   25
              .7657
My JVM is taking a lot of time to give the output.


Please help.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use a thread subject which tells people what the question is about.
How long does your program run for? What results do you get? Why are you writing what appears to be a main method with a double parameter? How many times do you think the loop will run?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There must be a much simpler way to find the fractional part of a floating‑point number. That will be impossible if there are too many digits because you will overwhelm the precision of the number types.
 
Anshul Kulkarni
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie, The program runs for I don't no how long but I don,t get an output at all. I expect the while loop to run as many times as the number of digits in the value of m.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look again. Go through the values of m and what they are going to be as the loop runs.

You can do that task (printing the two parts of a number) quite simply without a loop.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!