Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

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

Suppose i the cable company represents the channels your tv

Suppose I the cable company represents the channels your TV has access to with a 64- bit integer. Each channel from 0 to 63 is represented by one bit, where 1 means the channel is enabled and 0 means the channel is disab ...

If the real interest rate is -15 per annum and the infla-

If the real interest rate is -1.5% per annum and the infla- tion rate is 3% per annum, then what is the present value of a $1,000,000 nominal payment next year?

Question suppose a task consists of 40 cpu access 20 memory

Question : Suppose a task consists of 40% CPU access, 20% memory access and 40% disk access. A CPU with 8 cores provides an effective speedup of only 4 over a singlecore CPU. What is system speed up (as defined by Amdahl ...

According to the alzheimers association alzheimers disease

According to the Alzheimer's Association, Alzheimer's disease affects 1 in 10 people over the age of 65. What would be the shape, mean, and standard error of the sampling distribution of the proportion who suffer from Al ...

Question when we studied clusters we discovered that

Question : When we studied clusters we discovered that semaphores, the mechanism we rely on for mutual exclusion, don't work, and so we studied message-passing as an alternative that does work on clusters. Why do semapho ...

The demand for salt is relatively price inelastic while the

The demand for salt is relatively price inelastic, while the demand for pretzels is relatively price elastic. How can you best explain why and elaborate your answer.

The measurements of the diametersnbspin inches of 12

The measurements of the diameters? (in inches) of 12 randomly chosen golf balls are listed. At alpha (α) = 0.05?, is there enough evidence to reject the claim that the standard deviation of the measurements of these diam ...

A study was conducted of pleas made by 1032 criminals among

A study was conducted of pleas made by 1,032 criminals. Among those criminals, 954 pled guilty, and 394 of them were sentenced to prison. Among the 78 of the other criminals, who pled not quilty, 58 were sentenced to pri ...

How should facebook and other companies protect privacy

How Should Facebook and Other Companies Protect Privacy While Letting People Share Their Information Between Apps and Services?

Question recall the on the spot courier service introduced

Question : Recall the On the Spot courier service introduced in Unit 1. The details of the package pickup and delivery process are described here. When Bill got an order, at first, only on his phone, he recorded when he ...

  • 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