Develop a complete java program that uses if-else constructs

Assignment Help Data Structure & Algorithms
Reference no: EM131588834

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.

Reference no: EM131588834

Questions Cloud

Find the value of a and b : Given that Aand Bhave the respective position vectors a and b, find the position vector of a point P on the line AB located between A and B.
Funding for long-term projects in the market : Question 1: Corporations get funding for long-term projects in the market of:
How do you create a model : How do you create a model (based on the attached data; Money Demand Regression) using:
Find position vector r of a point on the straight line : Find the position vector r of a point P on the straight line joining point Aat (1, 2, 1) and point B at (3, -1, 2).
Develop a complete java program that uses if-else constructs : ITSD322 – Data Structures and Implementation
What are some details that stood out through performance : What parts of the play are easier to understand through performance? What are some details that stood out through performance?
Doubling time for france per capita real gdp : Compute the doubling time for France's per capita real GDP. Compute the doubling time for Korea's per capita real GDP.
Provide context as to where it fits in larger organization : Provide context as to where it fits in the larger organization. Compare the total number of employees of both organizations.
State whether you think taxpayer monies should support : State whether you think taxpayer monies should support research on this topic or whether such research in this area should be funded by the private sector.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd