Filters
Question type

Code a method that returns an int array that is parallel to its array parameter letters. If an element of letters is A, the corresponding element of the returned array is 1; otherwise, it is 0. Example 1: If the array parameter is A B A, the returned array is 1 0 1. Example 2: If the array parameter is A B A C D A A, the returned array is 1 0 1 0 0 1 1. Example 3: If the array parameter is A A E F G, the returned array is 1 1 0 0 0. public static int [ ] convert( char [ ] letters ) { // Your code goes here }

Correct Answer

verifed

verified

public static int [ ] convert( char [ ] ...

View Answer

If you want to use the Random class in your program, what statement must you have at the beginning of your program? Import only the Random class.

Correct Answer

verifed

verified

import jav...

View Answer

The variable numbers is a two-dimensional array of type int. Output all of its elements that are strictly greater than 10.

Correct Answer

verifed

verified

for( int i = 0; i < numbers.le...

View Answer

We have coded the following sequence: try { Scanner scan = new Scanner( new File( "data.txt" ) ); System.out.println( "ABC" ); } catch( FileNotFoundException fnfe ) { System.out.println( "DEF" ); } catch( Exception e) { System.out.println( "GHI" ); } It compiles and runs; the output is DEF. What conclusion can you draw from looking at the output?

Correct Answer

verifed

verified

The file d...

View Answer

Give the values that are assigned to each variable after the statements below are executed. -int a = 5 / 3; __________

Correct Answer

verifed

verified

The class Ticket has been coded as follows: public class Ticket { private double price; private char service; public Ticket( double newPrice, char newService ) { setPrice( newPrice ); setService( newService ); } } Consider the following constant of class Ticket: public static char DEFAULT_SERVICE = 'B'; In a client class and inside main, write a statement to output the value of the above constant.

Correct Answer

verifed

verified

System.out.println( ...

View Answer

If an int instance variable has an initial value of 10, what can you infer about the constructor for that value?

Correct Answer

verifed

verified

The constructor was written to...

View Answer

We have already coded the class User. It includes the instance variables name, age, and email, an overloaded constructor, and the toString method coded as follows: public String toString( ) { // return some String representation of this User object } We are now coding the class SuperUser, which inherits from User. SuperUser has one instance variable, fee, which is a double. We want the toString method of the SuperUser class to return the same String as the toString method of the User class, plus a semicolon, a space, and the value of fee. Example 1: If the toString method of User returns Mike, 23, HYPERLINK "mailto:mike@msn.com" mike@msn.com, and the value of fee is 19.9, the toString method of SuperUser returns Mike, 23, HYPERLINK "mailto:mike@msn.com" mike@msn.com, 19.9. Example 2: If the toString method of User returns Jane, 22, HYPERLINK "mailto:jane@gmail.com" jane@gmail.com, and the value of fee is 24.9, the toString method of SuperUser returns Jane, 22, HYPERLINK "mailto:jane@gmail.com" jane@gmail.com, 24.9. Code the toString method of the SuperUser class here. Assume that we do not know what the toString method of User returns.

Correct Answer

verifed

verified

public String toStri...

View Answer

Write Java statements to instantiate a random number generator object and generate a random integer between 100 and 250 (inclusive).

Correct Answer

verifed

verified

Random random = new ...

View Answer

Consider the following method: public static int foo( String s1, String s2, int i ) { if ( s2.length( ) > s1.length( ) ) return -1; else if ( s1.substring( 0, s2.length( ) ).equals( s2 ) ) return i; else return foo( s1.substring( 1, s1.length( ) ), s2, i + 1 ); } What is the output of the following code? System.out.println( foo( "AB", "XYZ", 0 ) ); What is the output of the following code? System.out.println( foo( "ABC", "A", 0 ) ); What is the output of the following code? System.out.println( foo( "ABCDEFG", "DE", 0 ) ); What does foo( s1, s2, 0 ) return as a function of s1 and s2?

Correct Answer

verifed

verified

// System.out.println( foo( "AB", "XYZ",...

View Answer

Showing 101 - 110 of 110

Related Exams

Show Answer