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", "done", or "d" for the line of text.   If my code is as follows how do I get it to advance in the list to the next element and print that on a new line as well.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter3: Input/output
Section: Chapter Questions
Problem 12SA: 12. What is the output of the following program? (2, 3, 6, 8) #include <iostream> #include...
icon
Related questions
Question

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", "done", or "d" for the line of text.  

If my code is as follows how do I get it to advance in the list to the next element and print that on a new line as well. 

Run your program as often as you'd like, before submitting for grading. Below, type any needed
Develop mode
Submit mode
input values in the first box, then click Run program and observe the program's output in the
second box.
Enter program input (optional)
Hey
Hello there
main.py
(Your program)
Output (shown below)
Run program
Input (from above)
Program output displayed here
yeH
Transcribed Image Text:Run your program as often as you'd like, before submitting for grading. Below, type any needed Develop mode Submit mode input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) Hey Hello there main.py (Your program) Output (shown below) Run program Input (from above) Program output displayed here yeH
5.17 LAB: Print string in reverse
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", "done", or "d" for the line of text.
Ex: If the input is:
Hello there
Неу
done
then the output is:
ereht olleH
yeH
274756.1776882
LAB
5.17.1: LAB: Print string in reverse
0/ 10
АCTIVITY
main.py
Load default template...
'' Type your code here.
2 greeting = input()
3 greetings 1ist = ['Hello there', 'Hey']
1
4
Transcribed Image Text:5.17 LAB: Print string in reverse 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", "done", or "d" for the line of text. Ex: If the input is: Hello there Неу done then the output is: ereht olleH yeH 274756.1776882 LAB 5.17.1: LAB: Print string in reverse 0/ 10 АCTIVITY main.py Load default template... '' Type your code here. 2 greeting = input() 3 greetings 1ist = ['Hello there', 'Hey'] 1 4
Expert Solution
Step 1 Code in Java

import java.util.Scanner;

public class PrintStringInReverse {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        while (!(s.equals("Done")||s.equals("done")||s.equals("d"))){
            for(int i = s.length()-1;i>=0;i--){
                System.out.print(s.charAt(i));
            }
            System.out.println();
            s = scan.nextLine();
        }
    }
}

 

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Time complexity
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning