Join 300,368 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,448 people online right now. Registration is fast and FREE... Join Now!
ok not 100% sure what you mean so ill give you a few examples of what you can do. note that you would need to say double in order for this to work, because you have a decimal
CODE
//1 double[] list = new double[20]; //2 double[] list = {23.23., 34.23, 8.3, 5, 23 ....}; //3 - not sure what you need this for so this might apply to you. double[] list; //then in your constructor you can have list = new double[20]; //or list = new double[size];
Virgul statements also apply to int as your first intention seemed to be int[] list = new int[20]; int[] list = {1, 2, 3}; int[] list; list = new int[10];
Indeed they would apply the same way however what Virgul was saying I think is that because she is using Prices - possible decimals. She needs to use an double.
//find the average (pbl's code) double total = 0.0; for(int i = 0; i < list.length; i++){ total = total + list[i]; } double average = total / list.length;
//print average System.out.println(average);
//if you need to print the whole list, then virgul's code for(int i = 0; i < list.length; i++){ System.out.println(list[i]); }
I don't know if you're still finding the average, or if you just want to print out the numbers. The concept is to just add an if statement (or more if needed), such as this:
CODE
if(list[i]<5.00) /*write whatever you need to do here when list[i] is less than 5.00*/;
ill let you figure out where to put this for yourself
C:\Java Working Directory>javac Prices.java Prices.java:13: cannot find symbol symbol : variable price location: class Prices double average = total/price.length; ^ Prices.java:15: cannot find symbol symbol : variable i location: class Prices if(prices[i]<5.00); ^ 2 errors
I've made corrections, but I'm still not getting it to compile. I also can get it to print out the values that are higher than the average.
HELP!
My next class is applets, and so far, I understand that! Thanks again, Mary