Scroll to see replies
public String nTwice(String str, int n) {
int stringLength = str.length();
String firstChars = str.substring(0,n);
String lastChars = str.substring(stringLength-n);
return firstChars+lastChars; }
•
•
A String, used to hold a sentence to manipulate
•
•
Take a String as a parameter, and assigns its value to the class variable
•
•
Take a String as a parameter, and return a new String that removes the first instance of the parameterString from the class variable.
•
As an example, if the argument is "cat", and the class variable stores "A kittycat is at the door", then the class method should return "A kitty is at the door".
•
As a second example, if the argument is "d", and the class variable stores "Candy is bad for your teeth", then the class method should return "Cany is bad for your teeth".
•
Note, for the purpose of this question, you can ignore the case where the parameter String does not appear in the class variable. This involves material we'll look at in Topic 3.
Last reply 1 minute ago
Official: King's College London A100 2024 Entry Applicants1020
Last reply 5 minutes ago
JK Rowling in ‘arrest me’ challenge over hate crime lawLast reply 9 minutes ago
NICS Staff Officer and Deputy Principal recruitment 2022 2023Last reply 15 minutes ago
Official: University of Manchester A106 2024 Entry Applicants1292
Last reply 16 minutes ago
The Official King's College London Applicants for 2024 Entry ThreadLast reply 18 minutes ago
Woodhouse College applicants 2024Last reply 19 minutes ago
BAE systems degree apprenticeships September 2024Last reply 21 minutes ago
OCR A-LEVEL PSYCHOLOGY PAPER 3 (H567/03) - 3rd June [Exam Chat]Last reply 23 minutes ago
OCR A-LEVEL PSYCHOLOGY PAPER 2 (H567/02) - 22nd May [Exam Chat]Last reply 24 minutes ago
Official University of Edinburgh Applicant Thread for 2024Last reply 25 minutes ago
Official: University of Bristol A100 2024 Entry ApplicantsLast reply 1 month ago
Free website hosting providers with no strings attached?Posted 3 months ago
iDEA silver citizen badge three. Milkshake shack coding problem.Last reply 4 months ago
How do you practice programming java for beginners?Last reply 8 months ago
iDEA run code error worker resolution badgeLast reply 1 month ago
Free website hosting providers with no strings attached?Posted 3 months ago
iDEA silver citizen badge three. Milkshake shack coding problem.Last reply 4 months ago
How do you practice programming java for beginners?Last reply 8 months ago
iDEA run code error worker resolution badge