Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write Java code that determines if each value 0 through 10 ispresent in the arra

ID: 3613870 • Letter: W

Question

Write Java code that determines if each value 0 through 10 ispresent in the array. If the array contains a value i, itwill print a message saying that i occurs in thearray.

Example:
Say the array contains these values: 3,10,3,11,0,10,3,-7,14,3
The code would print out:
Occurs in array: 0
Occurs in array: 3
Occurs in array:10

This is what I have but it prints the values in the array multipletimes. How can I get it to just print out the
values inside the array once?

int[] list = { 3, 10, 3, 11, 0, 10,3,-7,14,3 };
    int i=0;
    for ( i=0; i < list.length; i++){
        if (list[i] >=0&& list[i]<=10)
           
    System.out.println("Occurs in array: " +list[i]);
      
      
        }
}
}

Explanation / Answer

You need to make a boolean array that checks whether the valueshave been printed. Then, each time you find the value, youcheck to see whether it has already been printed in the array. publicstatic void main(String[]args) { int[] list= { 3, 10, 3, 11, 0, 10,3,-7,14,3 }; int i=0; boolean[] printed= newboolean[11]; //0 through 10 inclusive for (i=0; i =0 &&list[i]
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote