Please write a java program
Instructions
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
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.
Get Answers For Free
Most questions answered within 1 hours.