Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import java.io.Serializable;
  2.  
  3. public class MyString implements Serializable {
  4. private String theString;
  5. private int stringLength;
  6.  
  7. public MyString(){
  8. theString = "";
  9. stringLength = 0;
  10. }
  11. public MyString(String s){
  12. theString = s;
  13. }
  14. public void setTheString(String theString) {
  15. this.theString = theString;
  16. }
  17. public String getTheString() {
  18. return theString;
  19. }
  20. public void setStringLength(int l){
  21. this.stringLength = l;
  22. }
  23. public int getStringLength(){
  24. return stringLength;
  25. }
  26. public String reverseTheString(){
  27. String reverse = "";
  28. for (int i = theString.length() - 1; i >= 0; i--)
  29. reverse += theString.charAt(i);
  30. return reverse;
  31. }
  32. public int determineLength(){
  33. return theString.length();
  34. }
  35. public String getSubString(){
  36. String subString = "";
  37. for (int i = 0; i < theString.length() - 2; i++)
  38. subString += theString.charAt(i);
  39. return subString;
  40. }
  41. public String toString(){
  42. return String.format("String: %s Length: %d", theString, stringLength);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement