Question

What output do we get? How do we get that output? Consider the following method :...

What output do we get? How do we get that output?

Consider the following method :

public static void processArray (int [] array) {

int x = 0;

for (int i = 0; i < array.length - 1; i++ ) {

if (array [i] < array [i+1]) {

System.out.println (i + 1) ;

        }

    }

}

In the left-hand column below are specific arrays of integers. Indicate in the right- hand column what value would be printed by method processArray if the integer array in the left-hand column is passed as its parameter (Note: the output can be empty , buy you need to specify it explicitly). Original Contents of Array Output into

int [] a1= {34} ;

processArray (a1) ;

int [] a2 = {7, 1} ;

processArray (a2) ;

int [] a3 = {14, 68};

processArray (a3) ;

int [] a4 = {1,2,3,4};

processArray (a4) ;

int [] a5 = {-34};

processArray (a5);

Homework Answers

Answer #1


int [] a1= {34} -> it will not print anything as it has only 1 element
int [] a2 = {7, 1} ->it will not print as 7 <1 is false
int [] a3 = {14, 68} -> it will print 1 as 14<68
int [] a4 = {1,2,3,4} -> it will print 1 2 3 as 1<2<3<4
int [] a5 = {-34} -> it will not print anything as it has only 1 element
Note : Please comment below if you have concerns. I am here to help youIf you like my answer please rate and help me it is very Imp for me


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Suppose the initial conditions of the economy are characterized by the following equations. In this problem,...
Suppose the initial conditions of the economy are characterized by the following equations. In this problem, we assume that prices are fixed at 1 (the price index is 100 and when we deflate, we use 1.00) so that nominal wealth equals real wealth. 1) C = a0 + a1 (Y - T) + a2 (WSM) + a3 (WRE) + a4 (CC) + a5 (r) 1’) C = a0 + a1 (Y - 200) + a2 (10,000) + a3 (15,000) +...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
Modify the following code by JAVA language Write a static method totalDurations that is passed the...
Modify the following code by JAVA language Write a static method totalDurations that is passed the parallel arrays from the main program. It creates a new pair of parallel arrays (phone numbers and durations, again) where each different incoming phone number is stored exactly once, and the duration is the total duration of all the calls from that phone number. It then prints these arrays. Nothing is returned. For example, if the arrays contain 555-1234 (duration 10), 555-4321 (duration 20),...
Do a theta analysis and count the number of computations it performed in each function/method of...
Do a theta analysis and count the number of computations it performed in each function/method of the following code: import java.io.*; import java.util.Scanner; class sort { int a[]; int n; long endTime ; long totalTime; long startTime; static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public sort(int nn) // Constructor { a = new int[nn]; n = nn; endTime= 0; totalTime =0; startTime =0; } public static void main(String args[]) throws IOException { System.out.print("\nEnter number of students: "); int nn =...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems...
8.15 *zyLab: Method Library (Required & Human Graded) This code works but there are some problems that need to be corrected. Your task is to complete it to course style and documentation standards CS 200 Style Guide. This project will be human graded. This class contains a set of methods. The main method contains some examples of using the methods. Figure out what each method does and style and document it appropriately. The display method is done for you and...
Complete the following program. This program should do the following: 1. Creates a random integer in...
Complete the following program. This program should do the following: 1. Creates a random integer in the range 10 to 15 for variable: allThreads, to create a number of threads. 2. Creates a random integer for the size of an ArrayList: size. 3. Each thread obtains a smallest number of a segment of the array. To give qual sized segment to each thread we make the size of the array divisible by the number of threads: while(size%allThreads != 0)size++ 4....
Give the output of the following program. Then explain what the foo() method does, in general,...
Give the output of the following program. Then explain what the foo() method does, in general, for a given input. Is foo() a tail-recursive method? Why or why not? class SomeThing {     public static void main(String args[]) {         System.out.println(foo(6));     }     private static int foo(int input) {         if (input <= 0) {             throw new RuntimeException("invalid input");         }         else if (input == 1) {             return 1;         }         else if (input %...
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
Complete the java code as per the comments public class Sorting {    ///////////////////////////////////////////////    //...
Complete the java code as per the comments public class Sorting {    ///////////////////////////////////////////////    // STEP 1 -- Make sorting methods generic    ///////////////////////////////////////////////       /**    * Re-orders the contents given array using the insertion sort algorithm.    *    * @param data The array to be sorted.    */    //TODO: Make me generic to work on any kind of Comparable data!    public static void insertionSort(int[] data)    {        int insert; // temporary...
The AssemblyLine class has a potential problem. Since the only way you can remove an object...
The AssemblyLine class has a potential problem. Since the only way you can remove an object from the AssemblyLine array is when the insert method returns an object from the last element of the AssemblyLine's encapsulated array, what about those ManufacturedProduct objects that are "left hanging" in the array because they never got to the last element position? How do we get them out? So I need to edit my project. Here is my AssemblyLine class: import java.util.Random; public class...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT