/* * Copyright (c) 2001 Matthew Feldt. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided the copyright notice above is * retained. * * THIS SOFTWARE IS PROVIDED ''AS IS'' AND WITHOUT ANY EXPRESSED OR * IMPLIED WARRANTIES. */ /** * ReverseEcho.java * * Java Examples In A Nutshell Copyright (c) 2000 David Flanagan * Exercise 1-4: * Write a program that interactively reads lines of input from the user and * prints them back out, reversed. The program should exit if the user types * "tiuq". * * @author Matthew Feldt * @version 1.0, 01/27/2001 16:42 */ package com.feldt.examples.basics; import java.io.*; public class ReverseEcho { public static void main (String args[]) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (true) { try { System.out.print("Type 'tiuq' to exit > "); String input = in.readLine(); if (input == null || input.equals("tiuq")) break; for (int i = input.length()-1; i >= 0; i--) System.out.print(input.charAt(i)); System.out.println(); } catch(IOException e) { System.err.println(e); } } } }