It is for a training class and I am stuck. I was hoping if I can see an example of something that works I can see what I am doing wrong. I am trying to write a Java program that searches an array of...

1 answer below »
It is for a training class and I am stuck. I was hoping if I can see an example of something that works I can see what I am doing wrong. I am trying to write a Java program that searches an array of positive integers and prints out the maximum values evenly divisible by 13 or 31. The array has the values 39, 93, 26, 62, 13, 31. The results should be printed out to the console. Here is what I came up with but it is not working:


public class Question6 {






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};


array = tempArray;


int mone = 13;


int mtwo = 31;


int result1 = array[0];


int result2 = array[0];


for(int i=1; i


{


if(array[i] > result1)


{


array[i] = result1;


result1 /= mone;


}


if(array[i] > result2)


{


array[i] = result2;


result2 /= mtwo;










System.out.println("Max Divisible by 13:"+result1);


System.out.println("Max Divisible by 31:"+result2
Answered Same DayMar 03, 2021

Answer To: It is for a training class and I am stuck. I was hoping if I can see an example of something that...

Bhagyesh answered on Mar 04 2021
147 Votes
public class Question6{
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};
array = tempArray;
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here