Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

10) assume you have the following java statement: Scanner input; Question - what

ID: 3623686 • Letter: 1

Question

10) assume you have the following java statement:

Scanner input;

Question - what does the variable input refer to?

11) write a valid statement to declare a variable called phrase of type string that initializes the variable to the phase " for your eyes only"

B) using the phase variable, how would you call a method to return the length of phase?

C) using the phase variable, how would you call a method to return the second word only ("your") from that variable and assign the result to a new string variable called second?

12) what valid java statement could be used to calculate the square root of an integer variable called entry

Explanation / Answer

10) input - once initialized - will be an object of type Scanner, used to read text from any source object that implements the "Readable" java interface. You use it to read stuff... 11) 2 easy ways to declare a string variable here: String phrase = new String("for your eyes only"); String phrase = "for your eyes only"; B) use the length() method with any string to get an integer number representing the length of that string like so: int length = phrase.length(); C) Split the phrase into words by using the string split() method and splitting based on space between words, this returns an array of words. split() requires the delimiter - in our case blank space - to be written as a regular expression, you can look these up there are plenty of examples online. For our case, we'll use "s", it means any whitespace character (tab, newline, space, new paragraph etc) String[] words = phrase.split("\s"); String second = words[1]; // words[0]= for while words[1]= your and words[2]=eyes and words[3]=only Hope this helps

Dr Jack
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote