• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 15 páginas
Examen

JAVA Chapter 4 Test Questions and Answers| Latest Update 100% Solved

Document preview thumbnail
Vista previa 2 fuera de 15 páginas

JAVA Chapter 4 Test Questions and Answers| Latest Update 100% Solved

Vista previa del contenido

JAVA Chapter 4 Test Questions and Answers|
Latest Update 100% Solved
Assume that name is a variable of type String that has been assigned a value. Write an
expression whose value is a String containing the first character of the value of name. So if the
value of name were "Smith" the expression's value would be "S". ✔️✔️name.substring(0,1)


Assume that name is a variable of type String that has been assigned a value. Write an
expression whose value is a String containing the second character of the value of name. So if
the value of name were "Smith" the expression's value would be "m". ✔️✔️name.substring(1,2)


Write an expression that results in a String consisting of the third through tenth characters of
the String s. ✔️✔️s.substring(2,10)


Assume that word is a variable of type String that has been assigned a value. Write an
expression whose value is a String consisting of the last three characters of the value of word.
So if the value of word were "biggest" the expression's value would be "est".
✔️✔️word.substring(word.length() - 3,word.length())


Given three String variables that have been declared and given values, firstName, middleName,
and lastName, write an expression whose value is the initials of the three names: the first letter
of each, joined together. So if firstName, middleName, and lastName, had the values "John",
"Fitzgerald", and "Kennedy", the expression's value would be JFK". Alternatively, if firstName,
middleName, and lastName, had the values "Franklin", "Delano", and "Roosevelt", the
expression's value would be "FDR". ✔️✔️"" + firstName.charAt(0) + middleName.charAt(0) +
lastName.charAt(0)


Assume that sentence is a variable of type String that has been assigned a value. Assume
furthermore that this value is a String consisting of words separated by single space characters
with a period at the end. For example: "This is a possible value of sentence."

, Assume that there is another variable declared, firstWord, also of type String. Write the
statements needed so that the first word of the value of sentence is assigned to firstWord. So, if
the value of sentence were "Broccoli is delicious." your code would assign the value "Broccoli"
to firstWord. ✔️✔️firstWord =
sentence.substring(0,sentence.indexOf(' '));


Assume that given, middle and family are three variables of type String that have been assigned
values. Write an expression whose value is a String consisting of the first character of given
followed by a period followed by the first character of middle followed by a period followed by
the first character of family followed by a period: in other words, the initials of the name. So if
the values of these three variables were "John" "Fitzgerald" "Kennedy", then the expression's
value would be "J.F.K.". ✔️✔️given.charAt(0) + "." + middle.charAt(0) + "." + family.charAt(0) + "."


Given a String variable named sentence that has been initialized, write an expression whose
value is the the very last character in the String referred to by sentence.
✔️✔️sentence.charAt(sentence.length() - 1)


Assume that word is a variable of type String that has been assigned a value. Assume
furthermore that this value always contains the letters "dr" followed by at least two other
letters. For example: "undramatic", "dreck", "android", "no-drip".


Assume that there is another variable declared, drWord, also of type String. Write the
statements needed so that the 4-character substring word of the value of word starting with
"dr" is assigned to drWord. So, if the value of word were "George slew the dragon" your code
would assign the value "drag" to drWord. ✔️✔️drWord = word.substring(word.indexOf("dr"),4);


Write a sequence of statements that finds the first comma in the String line, and assigns to the
variable clause the portion of line up to, but not including the comma. You may assume that an
int variable pos, as well as the variables line and clause, have already been declared. ✔️✔️pos =
line.indexOf(',');
clause = line.substring(0,pos);

Información del documento

Subido en
21 de marzo de 2025
Número de páginas
15
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$11.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
KateJones
4.8
(12)
Vendido
32
Seguidores
0
Artículos
5716
Última venta
1 mes hace




Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes