Advertisement
IrinaIgnatova

Text Processing-Reverse Strings

Jul 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.util.*;
  5. import java.util.stream.Collectors;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.  
  11.         Scanner scanner = new Scanner(System.in);
  12.  
  13.         String input = scanner.nextLine();//hello започвам от последния char, който е на позиция i=input.length-1;
  14.         String reversed = "";
  15.         while (!input.equals("end")) {
  16.  
  17.             for (int i = input.length() - 1; i >= 0; i--) {
  18.                 reversed += input.charAt(i);
  19.             }
  20.             System.out.printf("%s = %s%n", input, reversed);//печатаме тук, иначе в изхода излиза и end
  21.             input = scanner.nextLine();
  22.             reversed = "";//зачиствам думата иначе ще присъедини резултата към предния reversed
  23.         }
  24.  
  25.  
  26.     }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement