Question 1: Write a program to read integers N1 and N2 from the input file “input4_03.txt”. Create an array of N1 integers where each integer is a random number in the range [1, N2] inclusively. Write a method for each of the following items and then print the results to the output file “output4_03.txt”

a. All elements in the array (method name: printAllElements(), input parameter: input array)

b. All odd numbers in the array (method name: printAllOdds(), input parameter: input array)

c. All even numbers in the array (method name: printAllEvens(), input parameter: input array)

d. The Maximum number(s) of the array (method name: printAllMaxs(), input parameter: input array)

e. The Minimum number(s) of the array (method name: printAllMins(), input parameter: input array)

f. The average of the array (method name: printAverage(), input parameter: input array)

g. All prime numbers in the array (method name: printAllPrimes(), input parameter: input array)

Question 2: Write a program that has only one method call allLess(). This method accepts two arrays of integers and returns true if each elements in the first array is less than the element at the same index in the second array, and return false otherwise. Your method should also return false if the arrays are not the same length. Test your method and print out to the screen in main() function the following calls

a. allLess(arr1, arr2); (where arr1 = [1,2,3,4,5], arr2 = [4,5,6,7,8]);
b. allLess(arr1, arr2); (where arr1 = [1,2,3,4,5], arr2 = [5,6,7,8]);
c. allLess(arr1, arr2); (where arr1 = [5,2,3,4,1], arr2 = [4,5,6,7,8]);
d. allLess(arr1, arr2); (where arr1 = [5,5,3,4,5], arr2 = [9,9,9,9,1]);

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.Scanner;

public class Question1 {

public static void main(String[] args) throws IOException
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output4_03.txt", false)));
Scanner input = new Scanner(new File("input4_03.txt"));
int n1, n2;
int[] array;
n1 = input.nextInt();
n2 = input.nextInt();
array = new int[n1];
for(int i = 0; i < n1; i++)
array[i] = (int)(Math.random() * n2 + 1);

By purchasing this solution you'll be able to access the following files:

for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats