Guest User

Untitled

a guest
Jul 15th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. package learn.java.udemy;
  2.  
  3. public class StringPractiseMethods {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7. StringPractiseMethods objs = new StringPractiseMethods();
  8. /*
  9. * objs.GetCharOfIndexWay1();
  10. * objs.GetCharOfIndexWay2();
  11. * objs.GetCharOfIndexWay3();
  12. * objs.GetIndexOfChar();
  13. * objs.PrintFromIndex();
  14. */
  15. objs.ReverseString();
  16.  
  17. }
  18.  
  19. public void GetCharOfIndexWay1() {
  20. // STRING IS A PREDEFINED CLASS PRESENT IN JAVA PACKAGE
  21. String str1 = "Payment $200 Paid";
  22.  
  23. System.out.println(str1.charAt(6));
  24. }
  25.  
  26. public void GetCharOfIndexWay2() {
  27.  
  28. String str2 = new String();
  29. str2 = "Payment $200 Paid";
  30. System.out.println(str2.charAt(8));
  31. }
  32.  
  33. public void GetCharOfIndexWay3() {
  34. String str3 = new String("Payment $200 Paid");
  35. System.out.println(str3.charAt(9));
  36. }
  37.  
  38. public void GetIndexOfChar() {
  39. String str4 = "Payment $200 Paid";
  40. // to print index number of particular value.
  41. System.out.println(str4.indexOf("2"));
  42. }
  43.  
  44. public void PrintFromIndex() {
  45. String str4 = "Payment $200 Paid";
  46. // to print from particular index
  47. System.out.println(str4.substring(8));
  48.  
  49. }
  50.  
  51.  
  52. public void ReverseString() {
  53. // Palindrome
  54. String s = "MADAM";
  55. // for concatenating 2 strings
  56. String m = "";
  57. for (int i = s.length() - 1; i >= 0; i--) {
  58. // System.out.println(s.charAt(i));
  59.  
  60. m = m + s.charAt(i);
  61.  
  62. }
  63.  
  64. System.out.println("Reverse is " + m);
  65.  
  66. if (s.equalsIgnoreCase(m)) {
  67. System.out.println(s + " is a PALENDROME ");
  68. } else {
  69. System.out.println(s + " is not a PALENDROME ");
  70. }
  71. }
  72.  
  73. }
Add Comment
Please, Sign In to add comment