Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*ReverseString
- * */
- import java.util.Scanner;
- public class reversestring {
- public static void main(String[]args) {
- String inStr;//input string
- String reverse = "";
- int inStrLen; //length of the input String
- Scanner in = new Scanner(System.in);
- System.out.print("Enter a String: ");
- inStr = in.next(); //use next() to read a string
- inStrLen = inStr.length();
- //use inStr.charAt(index) in a loop to extract character at "index" from inStr
- // The string's index begins at 0 from the left.
- for (int i = inStrLen - 1; i >= 0; --i) { //Process the
- String from the right
- reverse = reverse + inStr.charAt(i);
- System.out.print("The reverse of string "+ inStr + " is "
- + reverse);
- }
- }
- }
- Enter a String: 234
- The reverse of string 234 is 4The reverse of string 234 is 43The
- reverse of string 234 is 432
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement