You are given a skeleton of Program 2, answer questions a) and b) below. a) Complete Program 2 based on the question (i)
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
You are given a skeleton of Program 2, answer questions a) and b) below. a) Complete Program 2 based on the question (i)
You are given a skeleton of Program 2, answer 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 TiArray { 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 class TestArray { public static void main (String[] args) { int size = 5; double [] datal = new double [size]; 1/1) 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 1/ii) call method printArray() to display all values in datal 17/(iv)call to method isAscending() to check whether elements in datal is in ascending order if ( System.out.println("Data is in ascending order"); Jelse
System.out.println("Data is not in ascending order"); TIArray t1= new TlArray(); //(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) + ":"); //(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++) { //(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: