Advertisement
veronikaaa86

01. Reverse Strings

Jul 5th, 2023
900
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.61 KB | None | 0 0
  1. package stringProcessing;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P01ReverseStrings {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String word = scanner.nextLine();
  10.         while (!word.equals("end")) {
  11.             String reversedWord = "";
  12.             for (int i = word.length() - 1; i >= 0; i--) {
  13.                 char symbol = word.charAt(i);
  14.  
  15.                 reversedWord = reversedWord + symbol;
  16.             }
  17.  
  18.             System.out.printf("%s = %s%n", word, reversedWord);
  19.  
  20.             word = scanner.nextLine();
  21.         }
  22.     }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement