Java: Test that a given array of integers of length 2 contains a 4 or a 7
Contains 4 or 7
Write a Java program to test that a given array of integers of length 2 contains a 4 or a 7.
Sample Solution:
Java Code:
Sample Output:
Original Array: [5, 7] true
Pictorial Presentation:
Flowchart:
For more Practice: Solve these Related Problems:
- Modify the program to check if the array contains 3 or 9 instead.
- Write a program to check if an array contains only prime numbers.
- Modify the program to count how many times 4 or 7 appear in the array.
- Write a program to check if all elements in an array are either 4 or 7.
Java Code Editor:
Previous: Write a Java program to create a new array of length 2 from two arrays of integers with three elements and the new array will contain the first and last elements from the two arrays.
Next: Write a Java program to rotate an array (length 3) of integers in left direction.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics