1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rom4ik [11]
4 years ago
9

Write a program that takes in a line of text as input, and outputs that line of text in reverse. The program repeats, ending whe

n the user enters "Quit", "quit", or "q" for the line of text. in java.
Computers and Technology
1 answer:
OLEGan [10]4 years ago
6 0

Answer:

The solution code is as below:

  1.        Scanner input = new Scanner(System.in);
  2.        System.out.print("Input a string: ");
  3.        String inStr = input.nextLine();
  4.        int strLen = inStr.length();
  5.        while(inStr.equals("Quit") != true && inStr.equals("quit") !=true && inStr.equals("q") != true){
  6.            for(int i= 0; i < strLen; i++){
  7.                System.out.print(inStr.charAt(strLen - 1 - i));
  8.            }
  9.            System.out.println();
  10.            System.out.print("Input a string: ");
  11.            inStr = input.nextLine();
  12.            strLen = inStr.length();

Explanation:

Firstly, we create a Scanner object,<em> input</em> (Line 1).

Next, we use the Scanner object nextLine() method to get a text input from user (Line 3).

We create a while loop and set the condition so long as the input text is not equal to "Quit", "quit" or "q" (Line 6), the program should proceed to print the input text in reverse (Line 8-10). To print the text in reverse, we can apply the expression<em> length of string - 1 - current index</em>.  This will ensure the individual letter is read from the last and print the text in reverse.

Next, prompt the user to input a new text (Line 13-14) and repeat the same process of printing text in reverse so long as the current input text is not "Quit", "quit" or "q".

You might be interested in
What format are a setups program file in before executed?
UkoKoshka [18]
.EXE as they are executable programs.  However, it depends on the operating system
6 0
3 years ago
The automatic number of worksheets that appear when you open a blank Excel workbook is ? 1.One 2.Three 3.Six 4.Ten
tresset_1 [31]
The answer is 2. Three.   The automatic number of worksheets that appear when you open a blank Excel workbook is three.  <span>Excel automatically fills it with three blank worksheets named Sheet1, Sheet2, and Sheet3. Oftentimes, you'll work with the first worksheet (Sheet1), and not realizing that you have two more blank worksheets to work with—not to mention that you could add more.</span>
3 0
3 years ago
If you have cut or copied a set of information, which procedure will NOT work to paste it back into the worksheet?
faust18 [17]
It will work because i did it 
7 0
3 years ago
What is the answers please
Gre4nikov [31]
which question are u referring too
6 0
3 years ago
How do u answer questions on brainly if ur on the app and on a phone. For me there is no answer button :(
Rudik [331]

Answer:

oh for me there is maybe try reloading?

Explanation:

8 0
3 years ago
Other questions:
  • Write a static method named textcount that takes a scanner representing a file as a parameter and that reports various statistic
    11·1 answer
  • Which computer tools allow you to communicate with coworkers, family,and friends
    8·1 answer
  • Which technology uses regular phone lines and transmits at speeds up to 256 kbps?
    15·2 answers
  • Employers will check you out on social media sites like Facebook, MySpace, and Twitter.
    6·2 answers
  • How long is the latency time of a typical hard-disk drive spinning at 360 revolutions per second?
    6·1 answer
  • What term is used to describe an individual's money and personal property? budget income assets finances
    12·2 answers
  • Write a program that uses these bounds and bisection search (for more info check out the Wikipedia page on bisection search) to
    8·1 answer
  • How does violating the SOLID principles make code hard to test?
    5·1 answer
  • Files and folders in UNIX can be removed using the
    8·1 answer
  • When did Microsoft released MS-Word 2016? S When did Microsoft released MS - Word 2016​
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!