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
Amazon Project management apprenticeship 2024Last reply 1 minute ago
My boyfriend left me because he said my breasts and butt were too smallLast reply 2 minutes ago
HSBC Degree Apprenticeship 2024Last reply 3 minutes ago
Official University College London Applicant Thread for 2024Last reply 4 minutes ago
emmanuella's study discussions #2: taking breaksLast reply 5 minutes ago
Official University of St Andrews Applicant Thread for 2024Last reply 8 minutes ago
Edexcel GCSE Geography A Paper 1 (1GA0/01) - 17th May 2024 [Exam Chat]Last reply 9 minutes ago
Customer Services Group - Operational Delivery - Administrative OfficersLast reply 10 minutes ago
Official Cambridge Postgraduate Applicants 2024 ThreadLast reply 10 minutes ago
AQA GCSE Physics Paper 1 (Higher Tier triple) 8463/1H - 22nd May 2024 [Exam Chat]Last reply 11 minutes ago
How to Write an A* Prose Essay (A-level English Lit)Last reply 12 minutes ago
Religion Politics and Society at King's College?Last reply 50 minutes ago
IDEA silver award entrepreneur resilienceLast 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 50 minutes ago
IDEA silver award entrepreneur resilienceLast 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