Question: These questions are java 1. Consider the following method: // Assume that n >= 0 public static String decimalToBinary( int n ) { System.out.println( n

These questions are java

1. Consider the following method:

// Assume that n >= 0

public static String decimalToBinary( int n )

{

System.out.println( "n = " + n );

if ( n == 0 || n == 1 ) return n + "";

else

return decimalToBinary( n / 2 ) + n % 2;

}

a. What is the output of the following code? decimalToBinary( 1 ); // the output, NOT the return value

b. What is the output of the following code? decimalToBinary( 6 ); // the output, NOT the return value

c. What is the output of the following code? decimalToBinary( 37 ); // the output, NOT the return value

2. Code a recursive method that counts how many times the value 100 is found in an array of integers. Write one statement showing how to use it.

3. Because the private instance variables of a class are not inherited, how can the methods of a subclass access the values of these private instance variables?

4. Solve the factorial of 6. Show your work.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!