array

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 4
Reputation: asong is an unknown quantity at this point 
Solved Threads: 0
asong asong is offline Offline
Newbie Poster

array

 
0
  #1
Nov 3rd, 2009
i have a question but am confuse
the question is create and array of random double floating point numbers,calculate and print the sum off all the numbers in the array.truncates all of the numbers in the array up to 7 decimal places and then calculate and print the sum of the truncated numbers.calculate and print the difference between the actual sum of the numbersand the sum of the truncated numbers.the part i understand was how to
then you can use the java.text.NumberFormat class.

double value = 5.9999999999999;
NumberFormat nf = NumberFormat.getInstance();
nf.setMaximumFractionDigits(7);
String displayValue = nf.format(value);
System.out.println(displayValue);

//should print >5.9999999
but i dont kbnow haw to create a random double floating point numbers it just confuse me ,can someon help me out?please
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,718
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 230
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso
 
0
  #2
Nov 3rd, 2009
What is the range of the random numbers? Because you can use the Math.random.
Check the API
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 158 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC