Question

Question 9 (10 points) Suppose an array of integers is considered special if it contains more multiples of 3 than multiples
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE TO COPY:

METHOD:

public static boolean checkSpecial(int arr[])
{
int[] count=new int[2];   
int n=arr.length;
for(int i=0;i<n;i++)
{
if(arr[i]%3==0)
{
count[0]++;
}
if(arr[i]%5==0)
{
count[1]++;
}
}
if(count[0]>count[1])
{
return true;
}

else{
return false;
}

}
  

FULL EXPLANATION OF THE CODE INCLUDING MAIN:

1 import java.util.Scanner; 2 public class Main 3 - { public static boolean checkSpecial(int arr[]), int[] count=new int[2];31 - public static void main(String[] args) { int [] arr=new int[6]; Scanner sc=new Scanner(System.in); // arr is declared wi

OUTPUT:

3 10 24 18 Special

Add a comment
Know the answer?
Add Answer to:
Question 9 (10 points) Suppose an array of integers is considered "special" if it contains more...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following program that reads a number of nonnegative integers into an array and prints...

    Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array.   Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...

  • JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a...

    JAVA 1.Write a static method named getMaxEven(numbers) which takes an array of positive integers as a parameter. This method calculates and returns the largest even number in the list. If there are no even numbers in the array, the method should return 0. You can assume that the array is not empty. For example: Test Result int[] values = {1, 4, 5, 9}; System.out.println(getMaxEven(values)); 4 System.out.println(getMaxEven(new int[]{1, 3, 5, 9})); 0 public static int --------------------------------------------------------------------------------- 2. Write a static method...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • In JAVA write a program that contains an array containing 10 integers (1 to 10). user...

    In JAVA write a program that contains an array containing 10 integers (1 to 10). user insert an integer from (1 to 10) , method is library sort or gapped insertion sort that will each sort the array and print it out to the console.

  • In Java Write a program that reads an arbitrary number of 25 integers that are positive...

    In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...

  • 1- takes a 1D integer array arr as a parameter and returns a boolean value. 2-...

    1- takes a 1D integer array arr as a parameter and returns a boolean value. 2- The method returns true if the argument array contains two distinct values such that the sum of those two values is equal to the first element of the array arr. Otherwise, it returns false. 3- Assume that arr contains only positive integers (greater than 0). Sample runs provided below. 4- Sample runs provided below. 5- Complete and place your code in the Question 3...

  • Create a class called Reverse that reverses an array of integers. The class should have two...

    Create a class called Reverse that reverses an array of integers. The class should have two method: - public static void reverse(int [] array) – Which calls the private recursive method, passing the array parameter and which two array elements should be swapped. - private static void reverseRecursive(int [] array, int startIndex, int endIndex) – Which swaps the two elements of the array parameter pointed to by the startIndex and endIndex parameters. The method should be called again, this time,...

  • *** using java application Q1. BST: 1. Write a method that takes an array A, as parameter (A contains the elements of a BST traversed in preorder) and returns the corresponding BST 2. Write a method...

    *** using java application Q1. BST: 1. Write a method that takes an array A, as parameter (A contains the elements of a BST traversed in preorder) and returns the corresponding BST 2. Write a method to list the nodes on the path from the root to a given node in the BST. 3. Write a recursive method to check if two BSTs are same. 4. Write a non-recursive method to check if two BSTs are same 5. Write a...

  • Write a C++ function, smallestIndex, that takes as parameters an int array and its size and...

    Write a C++ function, smallestIndex, that takes as parameters an int array and its size and returns the index of the first occurrence of the smallest element in the array. To test your function, write a main that prompts a user for a list of 15 integers and outputs the index and value of the first occurrence of the smallest value. The program should print out Enter 15 integers: The position of the first occurrence of the smallest element in...

  • Questions Write a method that returns the union of two array lists of integers using the...

    Questions Write a method that returns the union of two array lists of integers using the following header: public static ArrayList<Integer> union(ArrayList<Integer> list1, ArrayList<Integer> list2) Write a test program that: 1. prompts the user to enter two lists, each with five integers, 2. displays their union numbers separated by exactly one space., and 3. finds the maximum number and the minimum number in the combined list. Here is a sample run of the program. Enter five integers for list1: 5...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT