This is JAVA
Priscilla Perfect detests imperfection (hence the name). Write a
program to analyze a given array and return true if the array is
worthy of being presented to Priscilla.
An array is considered perfect if there are no empty slots. Empty
slots in the given array will have a value of 0.
Examples:
isPerfectArray({2, 3, 4, 5, 6}) -> true isPerfectArray({1, 1, 4, 5, 6, 0, 0, 0, 0}) -> false
1
public boolean isPerfectArray(int[] arr)
2
{
3
4
}
public class PerfectArray { public boolean isPerfectArray(int[] arr) { for (int i = 0; i < arr.length; i++) { if (arr[i] == 0) return false; } return true; } public static void main(String[] args) { System.out.println(new PerfectArray().isPerfectArray(new int[]{2, 3, 4, 5, 6})); System.out.println(new PerfectArray().isPerfectArray(new int[]{1, 1, 4, 5, 6, 0, 0, 0, 0})); } }
Get Answers For Free
Most questions answered within 1 hours.