Question
What is the value in the variables x, y, and z after the following statements execute (assume each variable below has already been declared)?
str = "the Bluenose in the sun";
x = str.substring(4, str.indexOf("in"));
y = x.length();
z = x.charAt(4);
find the answers for the questions below:
Value of x:
Value of y:
Value of z:
str = "the Bluenose in the sun";
x = str.substring(4, str.indexOf("in"));
y = x.length();
z = x.charAt(4);
find the answers for the questions below:
Value of x:
Value of y:
Value of z:
Answers
oobleck
read the documentation of str.substring, and things should be clear.
Remember that strings are indexed starting at zero.
There are lots of examples online. See what you come up with.
Remember that strings are indexed starting at zero.
There are lots of examples online. See what you come up with.
anonymous
for x, i got: Bluenose
for y, i got: 9
for z, i got: 110
my assignment says that x, y and z is wrong. but i copied it this java program in my java editor and and it gave x = Bluenose, y =9 and z= 110
for y, i got: 9
for z, i got: 110
my assignment says that x, y and z is wrong. but i copied it this java program in my java editor and and it gave x = Bluenose, y =9 and z= 110
oobleck
for x, you will also get the trailing space
y is correct, oddly enough, since the length of "Bluenose" is only 8.
z is a char, not an int
y is correct, oddly enough, since the length of "Bluenose" is only 8.
z is a char, not an int
anonymous
thanks oobleck