You are given a skeleton of Program 2, answer questions a) and b) below. a) Complete Program 2 based on the question (i)
Posted: Fri May 20, 2022 11:45 am
questions a) and b) below. a) Complete Program 2 based on the question (i) to (ix) in comments provided. // Program 2 import java.util.Scanner; class TlArray public void changeElement(int num) { num = num+5; } public void changeArray (int[] dArray){ for (int i=0; i<dArray.length; i=i+2) { dArray=dArray*3; } public class TestArray { public static void main(String[] args) { int size = 5; double [] datal = new double (size); 1/60) declare another integer array named data2 using initializer list and initialized with values: 8, 7, 6, 2, 8 and 5 {8,7,6,2,8,5}; //(ii) call method inputData() to assign values for datal //(ii) call method printArray() to display all values in datal 1/(iv) call to method isAscending() to check whether elements in datal is in ascending order System.out.println("Data is in ascending order"); else System.out.println("Data is not in ascending order"); TlArray t1= new TlArray(); //(v) call method changeElement() and pass the fourth element of array data2 //(vi) call method changeArray() and pass array data2
TlArray t1= new TIArray(); //(v) call method changeElement() and pass the fourth element of array data2 //(vi) call method changeArray() and pass array data2 } public static void inputData(double[] arr) { Scanner kb= new Scanner(System.in); System.out.println("Enter a series of " + arr.length + "numbers."); for (int i=0; i<arr.length; i++) { System.out.print("Enter number" + (i+1) + ":"); 1/(vii)assign input to elements of datal public static boolean isAscending( double [] array) { boolean inOrder = true; for (int j=0; j<array.length-1; j++) 1/(viii) compare elements of the array if inOrder = false; } return inOrder; } public static void printArray(double [] array){ System.out.println("\nThe content of array datal:"); // (ix) use enhanced for-loop to print all elements of the array for item : System.out.println } b) What is the content of array data2 after Program 2 is executed? Content of array data2[] after execution of Program 2:
You are given a skeleton of Program 2, answer TlArray t1= new TIArray(); //(v) call method changeElement() and pass the fourth element of array data2 //(vi) call method changeArray() and pass array data2 } public static void inputData(double[] arr) { Scanner kb= new Scanner(System.in); System.out.println("Enter a series of " + arr.length + "numbers."); for (int i=0; i<arr.length; i++) { System.out.print("Enter number" + (i+1) + ":"); 1/(vii)assign input to elements of datal public static boolean isAscending( double [] array) { boolean inOrder = true; for (int j=0; j<array.length-1; j++) 1/(viii) compare elements of the array if inOrder = false; } return inOrder; } public static void printArray(double [] array){ System.out.println("\nThe content of array datal:"); // (ix) use enhanced for-loop to print all elements of the array for item : System.out.println } b) What is the content of array data2 after Program 2 is executed? Content of array data2[] after execution of Program 2: