44.9k views
0 votes
What output is produced by the following program?

public class Weird {
public static void main(String[] args) {
int number = 8;
halfTheFun(11);
halfTheFun(2 - 3 + 2 * 8);
halfTheFun(number);
System.out.println("number = " + number); }
public static void halfTheFun(int number) {
number = number / 2;
for (int count = 1; count <= number; count++) {
System.out.print(count + " "); }
System.out.println();
}
}

1 Answer

6 votes

Answer:

The correct output of the following question as follows:

1 2 3 4 5

1 2 3 4 5 6 7

1 2 3 4

number=8

Step-by-step explanation:

In the program, there is the main class name Weird. In that class, there is a main method and one function name (halfTheFun). In this function, we pass one parameter and call the function 3 times.

In first time calling, we pass the value 11. It is divided by 2 the answer 5 because (/) takes Quotient. Then use the for loop it is an entry control loop. It starts from 1 and equal to the number and print the value one by one.

In Second time calling, we pass the value(2 - 3 + 2 * 8) that is 15. It is divided by 2 the answer 7 because (/) takes Quotient. Then we use for loop. It starts from 1 and equal to the number and print the value one by one.

In the third time calling, we pass the value 8. It is divided by 2 the answer 4 because (/) takes Quotient. Then we use for loop. It starts from 1 and equal to the number and print the value one by one.

and we print the number.

OUTPUT:

1 2 3 4 5

1 2 3 4 5 6 7

1 2 3 4

number=8

User Rob Allen
by
5.3k points