Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package TextProcessing;
- import java.util.Scanner;
- public class ReverseStrings_01 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String word = scanner.nextLine(); //"end" или на друг текст
- //повтарям: въвеждам нова дума
- //спирам: дума == "end"
- //продължавам: дума != "end"
- while (!word.equals("end")) {
- //дадената дума -> "Softuni"
- //обратен ред -> "inutfoS"
- String reversedWord = getReversedWord(word);
- //"{word} = {reversed word}"
- System.out.println(word + " = " + reversedWord);
- word = scanner.nextLine();
- }
- }
- private static String getReversedWord(String word) {
- //table -> elbat
- String reversedWord = "";
- for (int position = word.length() - 1; position >= 0 ; position--) {
- char currentSymbol = word.charAt(position);
- reversedWord += currentSymbol;
- }
- return reversedWord;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment