Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Minimum and Maximum Array Problem

$
0
0
Here is the assignment: Write a method called countInRange that accepts an array of integers, a minimum value, and a maximum value as parameters and returns the count of how many elements from the array fall between the minimum and maximum (inclusive). For example, in the array {14, 1, 22, 17, 36, 7, -43, 5}, there are four elements whose values fall between 1 and 40.
Test Data: 12, 18, 21, 22, 1, 31, 5, 10, 34, 40, 67, 57
Min Number = 1
Max Number = 40
So far I have managed to come up with this code, but I still can't seem to get my program to work.
import java.util.Scanner;
public class ArrayProblem3
{
public static void main (String [] args)
{
Scanner in = new Scanner (System.in);
int [] data = new int [13];
int max = 0;
int min = 0;
int x = 0;
//Asks the user to input a minimum value
System.out.println ("Please enter in a minimum number:");
min = in.nextInt ();
//Asks the user to input a maximum value
System.out.println ("Please enter in a maximum number:");
max = in.nextInt ();

for (int n = 0; n < 12; n ++)
{
//Asks the user to input in 12 integers.
System.out.println ("Please enter in 12 integers");
x = in.nextInt ();
}


if (min > x && x < max)
{
	data [x] ++;
//Displays how many numbers are in the range.
System.out.println ("There are" + data [n] + "numbers in the range");
}





}





}
I am getting 1 error.


H:\AP Computer Science\ArrayProblem3.java:30: cannot find symbol
symbol : variable n
location: class ArrayProblem3
System.out.println ("There are" + data [n] + "numbers in the range");
^
1 error

Tool completed with exit code 1

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>