JAVA: Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending when the user enters “done” (case-insensitive) for the line of text.
Note: You are not supposed to use any in-build methods to reverse the text.
Example:
Enter a series of strings:
Hello there
Hey
done
the output is:
ereht olleH
yeH
import java.util.Scanner; public class PrintStringInReverse { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a series of strings:"); String s = scan.nextLine(); while (!(s.equalsIgnoreCase("done"))){ for(int i = s.length()-1;i>=0;i--){ System.out.print(s.charAt(i)); } System.out.println(); s = scan.nextLine(); } } }
Get Answers For Free
Most questions answered within 1 hours.