Exam 1: Review of Java Fundamentals

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Suppose temp is an array of 12 double values that holds the average temperatures of the 12 months of the year,January through December,in that order.Use Java to find the average of the temperatures for the 3 summer months,June,July and August only,and set this answer to the variable summerAverage.

(Essay)
4.7/5
(34)

The following code containing a loop attempts to find how many times the letter 'r' appears in a string.But something is wrong with the loop.How would you fix it? String s = "railroad"; int count = 0; char letter = s.charAt(index); for (int index = 0;index < s.length();++index) if (letter == 'r') ++count;

(Essay)
4.8/5
(39)

Suppose a try block needs to be followed by two catch blocks,each catching a different exception.Which exception should be caught first?

(Multiple Choice)
4.8/5
(39)

What is the value of sum after the following code executes? int sum = 0; int count = 0; while (count < 4) { sum += count / 2; count += 1; }

(Short Answer)
4.9/5
(40)

A comment in Java that begins with /** and ends with */ is what kind of comment?

(Multiple Choice)
4.9/5
(38)

How is the finally keyword used in Java?

(Multiple Choice)
4.9/5
(30)

Consider the following code that appears in a test class. A a = new A(); Int c = a.b; In order for this code to work,which statement must be true?

(Multiple Choice)
4.8/5
(38)

A default constructor requires at least one parameter in order to compile correctly.

(True/False)
4.8/5
(40)

Interpret the overall meaning of this if-statement: if (num % 7 == 0 || num % 11 == 0)

(Essay)
4.8/5
(37)

If we wanted to write an if-statement that executes whenever the real number x is between 10.0 and 20.0,how should the test condition be written?

(Multiple Choice)
4.9/5
(48)

Which of the following is an example of a wrapper class?

(Multiple Choice)
4.8/5
(41)

What is wrong with this Java statement? int num = new int(5);

(Essay)
4.9/5
(37)

A built-in class that helps to split strings into pieces,such as words of a sentence,is:

(Multiple Choice)
4.9/5
(32)

If s1 is of type String,what does s1.compareTo(s1)return?

(Multiple Choice)
4.8/5
(45)

In Java,how do we tell the compiler that the body of a loop consists of several statements,rather than one?

(Multiple Choice)
5.0/5
(32)

Suppose s is of type String.What would it mean if s.lastIndexOf)returns the value 1?

(Multiple Choice)
4.9/5
(34)

How many times are the indicated statements (#1)and #2)each executed? for (int i = 1;i <= 10;++i) for (int j = 1;j <= 10;++j) for (int k = 1;k <= 5;++k) ++count; // statement #1 System.out.printf("%d\n",count);// statement #2

(Essay)
4.7/5
(37)

Complete the following code so that it sets found to true if the array a consisting of integers contains the value zero. int index = 0; boolean found = false;

(Essay)
4.8/5
(39)

Suppose a class Planet had a method findLife( )that we call as follows in main( ): int value = p.findLife("goat",true,0.5); How would the findLife( )method be declared in Planet.java?

(Short Answer)
4.9/5
(39)

Which of these is not a legal Java identifier?

(Multiple Choice)
4.8/5
(38)
Showing 21 - 40 of 60
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)