Results 1 to 11 of 11
Thread: how to count numbers under 5.5
- 05-10-2011, 04:57 AM #1
-
- 05-10-2011, 05:06 AM #3
-
You need two constructs for this to work. First you have to go through all of the numbers in the array -- what code structure will allow you to loop through each item in the array?
- 05-10-2011, 05:12 AM #5
-
- 05-10-2011, 06:36 AM #7
Beware when using floating point numbers in equality statements.
Java Code:class DoubleTrouble { public static void main(String[] args) { int count = 0; double[] values = {1, 7.0, 5.4, 5.5, 5.6, 5.499999999999999999999999999999}; for(double d : values) { if(d < 5.5) { count++; } } System.out.println(count); } }
- 05-10-2011, 06:26 PM #8
- 05-10-2011, 06:28 PM #9
- 05-10-2011, 06:31 PM #10
Can anyone tell me the difference between:
Java Code:double[] numbers = new double[]{1.0, 1.5, 2.0, 2.5, 3.0, 3.5};
Java Code:double[] numbers = {1.0, 1.5, 2.0, 2.5, 3.0, 3.5};
Java Code:double numbers[] = {1.0, 1.5, 2.0, 2.5, 3.0, 3.5};
Are these codes just the same?
- 05-10-2011, 06:53 PM #11
Similar Threads
-
How to count random numbers together?
By krechlich in forum New To JavaReplies: 2Last Post: 04-04-2011, 08:29 PM -
Problem getting numbers from user and finding smallest two numbers
By radhi16 in forum New To JavaReplies: 11Last Post: 01-14-2011, 07:36 PM -
Count the numbers of parameters programmatically that a method has in JAVA?
By rsegecin in forum Advanced JavaReplies: 2Last Post: 10-24-2010, 05:34 PM -
printing two smallest numbers from a series of numbers
By trofyscarz in forum New To JavaReplies: 2Last Post: 10-15-2008, 12:46 AM -
Getting row count
By Java Tip in forum Java TipReplies: 0Last Post: 02-11-2008, 09:49 AM
Bookmarks