Ask Computer Engineering Expert

1. Which of the following statements will print a single line containing "hello there"?
a. System.out.println ( "hello" ); System.out.println( " there" );
b. System.out.println ( "hello" , " there" );
c. System.out.println ( "hello" ); System.out.print ( " there" );
d. System.out.print ( "hello" ); System.out.println( " there" );

2. What is the value of result after the following Java statements execute?
int a, b, c, d; a = 4;
b = 12;
c = 37;
d = 51;
result = d % a * c + a % b + a;
a. 119
b. 51
c. 127
d. 59

3. What will be output after the following Java statements have been executed?
int a, b, c, d; a = 4;
b = 12;
c = 37;
d = 51;
if ( a < b )
System.out.println( "a < b" ); if ( a > b )
System.out.println( "a > b" ); if ( d <= c )
System.out.println( "d <= c" ); if ( c != d )
System.out.println( "c != d" );

a. a < b c != d
b. a < b d <= c c != d
c. a > b c != d
d. a < b c < d a != b

4. What is output by the following Java code segment?
int temp; temp = 200;
if ( temp > 90 )
System.out.println( "This porridge is too hot." ); if ( temp < 70 )
System.out.println( "This porridge is too cold." ); if ( temp == 80 )
System.out.println( "This porridge is just right!" );
a. This porridge is too hot.

b. This porridge is too cold.
c. This porridge is just right!
d. None of the above.

5. What is output by the following Java code segment?
int temp; temp = 180;
if ( temp > 90 ) {
System.out.println( "This porridge is too hot." );
// cool down
temp = temp - ( temp > 150 ? 100 : 20 );
}
else {
if ( temp < 70 ) {
System.out.println("This porridge is too cold.");
// warm up
temp = temp + (temp < 50 ? 30 : 20);
}
}
if ( temp == 80 )
System.out.println( "This porridge is just right!" );
a. This porridge is too hot.
b. This porridge is too cold. This porridge is just right!
c. This porridge is just right!
d. None of the above.

6. What is output by the following Java code segment?
int temp; temp = 180;
while ( temp != 80 ) { if ( temp > 90 ) {
System.out.print( "This porridge is too hot! " );
// cool down
temp = temp - ( temp > 150 ? 100 : 20 );
}
else {
if ( temp < 70 ) { System.out.print(
"This porridge is too cold! ");
// warm up
temp = temp + (temp < 50 ? 30 : 20);
}
}
}
if ( temp == 80 )
System.out.println( "This porridge is just right!" );
a. This porridge is too cold! This porridge is just right!
b. This porridge is too hot! This porridge is just right!
c. This porridge is just right!
d. None of the above.

7. A Java class can have which of the following methods?
A. foo( int a )
B. foo( int a, int b )
C. foo( double a )
D. foo( double a, double b )

E. foo( int b )
a. All of the above.
b. A, B, D, E.
c. A, B, C, D.
d. A, C, D, E.
8. Which of the following statements about arrays are true?
A. Arrays are a group of contiguous memory locations, where each location is an element.
B. Elements are located by subscript or index.
C. The length of array c is determined by the expression c.length();
D. The seventh element of array c is specified by c[7].
a. A, C, D.
b. A, B.
c. C, D.
d. A, B, C, D.

9. Consider the array:

s[0]

7

s[1]

0

s[2]

-12

s[3]

9

s[4]

10

s[5]

3

s[6]

6

The value of s[ s[6] - s[5] ] is:
a. 0.
b. 3.
c. 9.
d. 0.

10. Consider the code segment below. Which of the following statements is not true.
1. int g[];
2. g = new int[ 23 ];
a. Statement 1 declares an array reference.
b. Statement 2 allocates the array.
c. g is a reference to an array of integers.
d. The value of g[ 3 ] is -1.

11. Which of the following initializer lists would correctly set the elements of array n? a. int n[] = {1, 2, 3, 4, 5 };
b. array n[ int ] = { 1, 2, 3, 4, 5 };
c. int n[ 5 ] = {1; 2; 3; 4; 5 };
d. int n = new int( 1, 2, 3, 4, 5 );

12. Consider the class below.
public class Test {
public static void main( String args[] )
{
int a[];
a = new int[ 10 ];
for ( int i = 0; i < a.length; i++ ) a[ i ] = i + 1 * 2;
int result = 0;
for ( int i = 0; i < a.length; i++ ) { result += a[ i ];

}
System.out.println( "Result is : " + result ); System.exit( 0 );
}
}
The output of this Java program will be:
a. Result is : 62.
b. Result is : 64.
c. Result is : 65.
d. Result is : 67.
13. Consider the program below:
public class Test {
public static void main( String args[] )
{
int a[] = { 99, 22, 11, 3, 11, 55, 44, 88, 2, -3 };
int result = 0;
for ( int i = 0; i < a.length; i++ ) { if ( a[ i ] > 30 )
result += a[ i ];
}
System.out.println("Result is : " + result ); System.exit( 0 );
}
}
The output of this Java program will be:
a. Result is : 280.
b. Result is : 154.
c. Result is : 286.
d. Result is : 198.
14. Constructors:
a. Have the same name as the class.
b. May not specify a return type.
c. Are called automatically when an object is instantiated.
d. All of the above.

15. An instance variable has which of the following scopes?
a. Block scope.
b. Method scope.
c. Class scope.
d. None of the above.

16. A package is:
a. A directory structure used to organize classes and interfaces.
b. A mechanism for software reuse.
c. A group of related classes and interfaces.
d. All of the above.

17. A constructor cannot:
a. Be overloaded.
b. Initialize variables to their defaults.
c. Specify return types or return values.
d. Have the same name as the class.

18. Instance variables declared final do not or cannot:
a. Use the principle of least privilege.

b. Be initialized.
c. Be modified.
d. Cause syntax errors if used as a left-hand value.

19. Develop a complete Java program that uses if-else constructs and a class called "Display" to prompt the user for an integer number. If the number is a negative integer, the program will call on the displayInfo() method from the class "Display" to display your first name, your last name, and the number, and then terminates. If the number is positive integer, the program will call on the displayInfo() method from the class "Display" to display your last name, your first name, and then terminates, otherwise, the program displays the string "Nothing processed...", and then terminates. You must use Exception Handling to detect and entry other than numeric value (InputMismatchException) and a General Exception.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92397548
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Does bmw have a guided missile corporate culture and

Does BMW have a guided missile corporate culture, and incubator corporate culture, a family corporate culture, or an Eiffel tower corporate culture?

Rebecca borrows 10000 at 18 compounded annually she pays

Rebecca borrows $10,000 at 18% compounded annually. She pays off the loan over a 5-year period with annual payments, starting at year 1. Each successive payment is $700 greater than the previous payment. (a) How much was ...

Jeff decides to start saving some money from this upcoming

Jeff decides to start saving some money from this upcoming month onwards. He decides to save only $500 at first, but each month he will increase the amount invested by $100. He will do it for 60 months (including the fir ...

Suppose you make 30 annual investments in a fund that pays

Suppose you make 30 annual investments in a fund that pays 6% compounded annually. If your first deposit is $7,500 and each successive deposit is 6% greater than the preceding deposit, how much will be in the fund immedi ...

Question -under what circumstances is it ethical if ever to

Question :- Under what circumstances is it ethical, if ever, to use consumer information in marketing research? Explain why you consider it ethical or unethical.

What are the differences between four types of economics

What are the differences between four types of economics evaluations and their differences with other two (budget impact analysis (BIA) and cost of illness (COI) studies)?

What type of economic system does norway have explain some

What type of economic system does Norway have? Explain some of the benefits of this system to the country and some of the drawbacks,

Among the who imf and wto which of these governmental

Among the WHO, IMF, and WTO, which of these governmental institutions do you feel has most profoundly shaped healthcare outcomes in low-income countries and why? Please support your reasons with examples and research/doc ...

A real estate developer will build two different types of

A real estate developer will build two different types of apartments in a residential area: one- bedroom apartments and two-bedroom apartments. In addition, the developer will build either a swimming pool or a tennis cou ...

Question what some of the reasons that evolutionary models

Question : What some of the reasons that evolutionary models are considered by many to be the best approach to software development. The response must be typed, single spaced, must be in times new roman font (size 12) an ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As