How to echo error from foreach loop?

Foreach not applicable to expression type - why am I getting this?

  • public static double[] adjustFrequency(double[] samples, double factor) { int newSamplesIndex = 0; double samplesIndex = 0; double[] newSamples = new double[samples.length]; for (int n : newSamplesIndex) if (n < newSamples.length-1) { newSamples[newSamplesIndex] = samples[(int)samplesIndex]; samplesIndex =+ factor; } return newSamples; } This method is part of a compsci assignment that does a series of operations on arrays, I need to use a foreach loop but I keep getting the error "Foreach not applicable to expression type". Any thoughts?

  • Answer:

    your calling foreach on a regular int. proper use for(int n : intarray) My best guess is you wanted to do something like for(double d : newSamples) { if (d ... etc }

Sansom at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.