Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class MyStringClass
  4. {
  5.  
  6. public String getString() {
  7. // Get console String input
  8. System.out.print("Enter a String: ");
  9. Scanner in = new Scanner(System.in);
  10. String str = in.nextLine();
  11. return (str);
  12. }
  13.  
  14. }
  15.  
  16. public class Assignment14 {
  17.  
  18. public static void main(String args[]){
  19.  
  20. System.out.println("Greetings: this program is written by Matt Weisfeld");
  21.  
  22. String reverseStr = "";
  23.  
  24. // create object instance
  25. MyStringClass myStrObject = new MyStringClass();
  26.  
  27. // get string from console
  28. String str = myStrObject.getString();
  29. System.out.println("You entered this string: " + str);
  30.  
  31. // print the reverse string
  32. int i = str.length() - 1;
  33. for ( ; i >= 0; i--){
  34. reverseStr = reverseStr + str.charAt(i);
  35. }
  36. System.out.println("The reversed string is:");
  37. System.out.println(reverseStr);
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement