Question
(JAVA) Using the provided code, write a program using the main method where it searches through an array of positive, non-zero integer values and prints
(JAVA)
Using the provided code, write a program using the main method where it searches through an array of positive, non-zero integer values and prints out the maximum values evenly divisible by 13 or 31. The program should use the array provided in the code (its identifier is array), and you may assume that it has already been populated with values. The results should be printed out to the console in the following format:
Max Divisible by 13: <
Values denoted in << >> represent variable values, and strings in quotations denote literal values (make sure to follow spelling, capitalization, punctuation, and spacing exactly). Also, if there are either no values evenly divisible by 13 or 31 then it should print out -1 for those values.
PLEASE PROVIDE BRIEF DESCRIPTION/SUMMARY OF HOW YOU GOT THE PROGRAM TO WORK (METHODS USED, ETC...)
import java.util.Scanner; public class Question03 {
public static int[] array;//The array to be used in the problem public static void main(String[] args) { if(args == null || args.length == 0) { //----------------------------------------------------------------------------------- int[] tempArray = {39, 93, 26, 62, 13, 31};//You may change these values to test your solution //Do not alter----------------------------------------------------------------------- array = tempArray; } //----------------------------------------------------------------------------------- //Write your solution here
}//Do not alter this //Space for other methods if necessary----------------------------------------------- //Write those here if necessary //----------------------------------------------------------------------------------- }//Do not alter this
SOLUTION TESTS
- If the array has the values {39, 93, 26, 62, 13, 31} does the program print out:
Max Divisible by 13: 39
Max Divisible by 31: 93
- If the array has the values {124, 62, 17, 93, 24, 12} does the program print out:
Max Divisible by 13: -1
Max Divisible by 31: 124
- If the array has the values {501, 790, 321, 592, 91} does the program print out:
Max Divisible by 13: 91
Max Divisible by 31: -1
- If the array has the values {200, 865, 824, 861, 330} does the program print out:
Max Divisible by 13: -1
Max Divisible by 31: -1
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started