I am working on an assignment and am stuck on one part. Searching my array to see if it contains the number 4. I am also having the problem of that answer repeating 10 times. I know why that is happening I just don't know how to fix it. I have been working on this problem since yesterday and it was smooth until I got to this section. Any bits of advice to point me in the right direction would be great. Below is the program;
import java.util.*;
public class Array {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
int[] running = new int[10];
int x;
int sum = 0;
int number;
for(x = 0; x < 10; x++)
{
running[x] = (int) (x*2.6 + 2.6);
System.out.println(running[x]);
}
for(x = 0; x < running.length; x++)
{
sum = sum + running[x];
}
System.out.println("The value for index 2 is: " + running[2]);
System.out.println("The list length is: " + running.length);
System.out.println("The total number of miles ran is: " + sum);
System.out.println("The average number of miles ran is: " +(double)sum/running.length);
for(x = 0; x < running.length; x++)
{
if (x == 4)
System.out.println(4 + " Does not exist.");
else
System.out.println(4 + " does exist.");
}
}
}
booleanvariable to store, if you have found a4and print that result after the loop.