Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class MyStringClass
- {
- public String getString() {
- // Get console String input
- System.out.print("Enter a String: ");
- Scanner in = new Scanner(System.in);
- String str = in.nextLine();
- return (str);
- }
- }
- public class Assignment14 {
- public static void main(String args[]){
- System.out.println("Greetings: this program is written by Matt Weisfeld");
- String reverseStr = "";
- // create object instance
- MyStringClass myStrObject = new MyStringClass();
- // get string from console
- String str = myStrObject.getString();
- System.out.println("You entered this string: " + str);
- // print the reverse string
- int i = str.length() - 1;
- for ( ; i >= 0; i--){
- reverseStr = reverseStr + str.charAt(i);
- }
- System.out.println("The reversed string is:");
- System.out.println(reverseStr);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement