Java - string

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What will be the tokens in the following statement? StringTokenizer strToken = new StringTokenizer("123-456-7890", "-", true);

123, 456, 7890, and -

What will be the value of loc after the following code is executed? int loc; String str = "The cow jumped over the moon." loc = str.indexOf("ov");

15

If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2? (1) (str1 < str2) (2) (str1.equals(str2) < 0) (3) (str1.compareTo(str2) < 0)

3

For the following code, how many times would the while loop execute? StringTokenizer strToken = new StringTokenizer("Cars, trucks, and SUVs are all types of automobiles."); while (strToken.hasMoreTokens) { System.out.println(strToken.nextToken()); }

9

If a non-letter is passed to the toLowerCase or toUpperCase method, it is returned unchanged.

True

If you are using characters other than whitespaces as delimiters, you will probably want to trim the string before tokenizing; otherwise, the leading and/or following whitespaces will become part of the first and/or last token.

True

What will be the value of matches after the following code is executed? boolean matches; String[] productCodes = {"456HI345", "3456hj"}; matches = productCodes[0].regionMatches(true, 1,productCodes[1], 2, 3)

True

In Java, when a character is stored in memory, it is actually as a(n) ________.

Unicode character code

Assuming that str is declared as follows, String str = "RSTUVWXYZ"; what value will be returned from str.charAt(5)?

W

In the following statement, what data type must recField be: str.getChars(5, 10, recField, 0);

char[]

What is the value of str after the following code has been executed? String str; String sourceStr = "Hey diddle, diddle, the cat and the fiddle"; str = sourceStr.substring(12,17);

diddl

To convert the string, str = "285.74" to a double and store it in the variable x, use the following statement

double x = Double.parseDouble(str);

If str is declared as String str = "ABCDEFGHI"; what will be returned from Character.toLowerCase(str.charAt(5))?

f

To use the class StringTokenizer, you must have the following import statement.

import java.util.StringTokenizer;

The Character wrapper class provides numerous methods for

string and converting char variables

When you are writing a program with String objects that may have unwanted spaces at the beginning or end of the strings, use the ____ method to delete them.

trim

To convert the int variable, number to a string, use the following statement.

String str = Integer.toString(number);

To convert the integer variable, number = 56, to a string, use the following statement.

String str = Integer.toString(number);

Which of the following statements will print the maximum value a double variable may have?

System.out.println(Double.MAX_VALUE);

Few programmers use wrapper classes because

They are immutable and they provide useful static functions (a) and (b)

What will be printed after the following code is executed? String str = "abc456"; int i = 0; while ( l < 6 ) { if (Character.isLetter(str.charAt(i)) System.out.println(Character.toUpperCase(charAt(i))); i++;

ABC

In a string that contains a series of words or other items of data separated by spaces or other characters, the programming term for the spaces or other characters is

Delimiter

StringBuffer objects are immutable

False

True/False The valueOf() method accepts a string representation as an argument and returns its equivalent integer value.

False

You must call a method to get the value of a wrapper class object.

False

What does the following statement do? Double number = new Double(8.8);

It creates a Double object initializes that object to 8.8 assigns the object's address to the number variable


Set pelajaran terkait

Frankenstein Chapter 6-8 Questions

View Set

New CA- Nutrition and cancer prevention

View Set

pre-calc radian/degree conversion

View Set

Employment Law: Chapter 5- Affirmative Action

View Set

Adult Health Chapter 49 Diabetes Mellitus EAQ Questions

View Set