uaveiro-leci/1ano/2semestre/poo/src/tp_codecheck/tp02/Strings1.md

2.1 KiB

Tabela Exercício 1 de Strings

Question Answer
What is the length of the string below?
String str = "Java Program"
12
With str as defined above, give a call to the substring method that returns the substring "gram". str.substring(8)
Use the string concatenation operator to change the string variable str to contain the string "Java Programming". str += "ming"
What does the following statement sequence print?

String str = "Harry";
int n = str.length();
String mystery = str.substring(0, 1) + str.substring(n - 1, n);
System.out.println(mystery);
Hy
Consider the following statement sequence. If the user provides the input John Q. Public, what is printed? If an error occurs, type error.

Scanner in = new Scanner(System.in);
String first = in.next();
String last = in.next();
System.out.println(last + ", " + first);
Q., John