Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();//hello започвам от последния char, който е на позиция i=input.length-1;
- String reversed = "";
- while (!input.equals("end")) {
- for (int i = input.length() - 1; i >= 0; i--) {
- reversed += input.charAt(i);
- }
- System.out.printf("%s = %s%n", input, reversed);//печатаме тук, иначе в изхода излиза и end
- input = scanner.nextLine();
- reversed = "";//зачиствам думата иначе ще присъедини резултата към предния reversed
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement