Question

Please write a java program Instructions Your goal is to take N integer inputs from the...

Please write a java program 

Instructions

  • Your goal is to take N integer inputs from the user -- N's value will be given by the user as well.
    • You can assume the user provides a valid value for N, i.e., >0.
  • Store the input integers in an array of size N in the order they are provided.
    • These tasks should be done in the main() method.
  • Create a new method called checkArray() that will take the previously created array as input from main().
  • Decide whether each member of the array is a multiple of 15 and 20 or not.
  • And, print the decision in the same way as shown below.
  • You can use the code structure given below.
  • If you do not follow any of the instructions, you will lose points.

Sample Outpu

What is the size of the array? 3

Give me 3 numbers. 10 20 15

10: !MULT15: !MULT20

20: !MULT15: MULT20

15: MULT15: !MULT20

Homework Answers

Answer #1

import java.util.Scanner;
public class Main{
        // this function checks if
        // a number is divisible by 15, 20  
        public int checkArray(int n){
                int status=0;
                if(n%15==0)
                        status+=1;
                if(n%20==0)
                        status+=2;
                
                return status;
        }
        
        public static void main(String[] args){
                // declare variables
                int n, i, result,data_count=0, process_count=0;
                
                // declare scenner class object
                Scanner sc=new Scanner(System.in);
                
                //declare object of class
                Main obj=new Main();
                
                // take input from user
                System.out.print("What is the size of the array? ");
                n=sc.nextInt();
                
                //Take input of n numbers
                // declare an array of size n
                int number[]=new int[n];
                
                System.out.print("Give me "+n+" numbers. ");
                // take input of n numbers
                for(i=0;i<n;i++)
                        number[i]=sc.nextInt();
                
                //check if each number is divisible 
                // by 15 or 25
                // call checkArray() in each iteration
                for(i=0;i<n;i++){
                        if(obj.checkArray(number[i])==0)
                                System.out.println(number[i]+": !MULT15:!MULT20");
                        else if(obj.checkArray(number[i])==1)
                                System.out.println(number[i]+": MULT15: !MULT20");
                        else if(obj.checkArray(number[i])==2)
                                System.out.println(number[i]+": !MULT15: MULT20");
                        else
                                System.out.println(number[i]+": MULT15: MULT20");
                }
        }
}

___________________________________________________________________

What is the size of the array? 5
Give me 5 numbers. 10 20 15 30 60
10: !MULT15:!MULT20
20: !MULT15: MULT20
15: MULT15: !MULT20
30: MULT15: !MULT20
60: MULT15: MULT20

___________________________________________________________________


Note: If you have queries or confusion regarding this question, please leave a comment. I would be happy to help you. If you find it to be useful, please upvote.

Know the answer?
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
Similar Questions
Instructions Write a Java code Your goal is to take N integer inputs from the user...
Instructions Write a Java code Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as input...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two...
IN JAVA PLEASE write code to MERGESORT an array of user inputted OBJECTS you have two different classes in the program being made as objects in the main (Bunny class and Dog Class). ask the user "what kind of animal would you like to sort?" user chooses the type of animal (bunny or dog), then you ask the user how big would you like the array of animals to be (maximum array size = 20)? and then you ask what...
c++ please 1. Write and test the function maximum that is passed an array of n...
c++ please 1. Write and test the function maximum that is passed an array of n pointers to integers and returns the maximum value among the n integers. The function must use the traveling pointer notation to traverse the array. you have to ask the user for the size of the array and ask the user to input the values in the main. The function has the following prototype. int maximum ( int *p [ ], int n);
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
Write a Java program that asks the user to enter an array of integers in the...
Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named isSorted that accepts an array of and returns true if the list is in sorted (increasing) order and false otherwise. For example, if arrays named arr1 and arr2 store [10, 20, 30, 41,...
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
(Write in C++) Write a program that reads in two numbers and, if the input is...
(Write in C++) Write a program that reads in two numbers and, if the input is valid, outputs 2 times the product of the integers that lie between the two values (including the values themselves). If either number is not an integer, or if the first number is not less than the second number, just output an error message. The sample runs below should give the idea. User inputs are in bold. Important Notes: Your program should use a loop...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
is there anything wrong with the solution. the question are from java course Write a main...
is there anything wrong with the solution. the question are from java course Write a main method that will request the user to enter Strings using a JOptionPane input dialog. The method should continue accepting strings until the user types “STOP”.       Then, using a JOptionPane message dialog, tell the user how many of the strings begin and end with a digit. Answer: import javax.swing.*; public class IsAllLetters {     public static void main(String[] args) {         String input;         int count =...
Write a program that takes n integer numbers from the user, and then counts the number...
Write a program that takes n integer numbers from the user, and then counts the number of even numbers and odd numbers and print them to the screen. Sample Output: Enter how many numbers you have: 10 Enter the 10 numbers: 1 3 19 50 4 10 75 20 68 100 The number of even numbers is: 6 The number of odd numbers is: 4 (( in java ))
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT