Ask Question
19 September, 05:36

Consider the following method.

public void printSomething (int num, boolean val) { num--; System. out. print (val); System. out. print (num); }

Consider the following code segment, which appears in a method in the same class as printSomething. printSomething (1, true); printSomething (2, true);

What is printed as a result of executing the code segment?

+4
Answers (1)
  1. 19 September, 05:41
    0
    The output of the given code as follows:

    Program:

    public class Main / /define class

    {

    public static void printSomething (int num, boolean val) / /define method.

    {

    num--; / /decrease value by 1.

    System. out. print (val); / /print value.

    System. out. print (num); / /print value.

    }

    public static void main (String[] args) / /main method

    {

    printSomething (1, true); / /calling function

    printSomething (2, true); / /calling function

    }

    }

    Output:

    true 0

    true 1

    Explanation:

    In the question, it is given there is a method that is "printSomething" is defined. This method accepts two parameters that are num and val. where num is an integer variable and val is boolean variable that holds two values only that are true or false. inside the method, we decrease the value of the num variable by 1 and then we print the value of val and num variable. This function does not return any value because we use return type void.

    The function is defined in the same class so, we call the function two times that can be described as:

    In first time calling we pass 1 and true value in function so it will "print true 0". In second time calling we pass 2 and true value in function so it will "print true 1".
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Consider the following method. public void printSomething (int num, boolean val) { num--; System. out. print (val); System. out. print ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers