Question

JAVA: Write a program that takes in a line of text as input, and outputs that...

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

Homework Answers

Answer #1
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();
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function that accepts a line of text and a single letter as input (case...
Write a function that accepts a line of text and a single letter as input (case insensitive) and returns the number of times the letter is the first character of a word. Note your program should be able to handle different cases. And check if the user input is a single letter. Example: Input text = "When the SUN rises at dawn, the chicken flies into the window." Input letter = "t" Output = "The letter t has appeared 3...
Prompt the user for a text string. Print each letter of the string to the console...
Prompt the user for a text string. Print each letter of the string to the console in reverse order. When finished print “I’m done” on a new line. Do not use any looping constructs to accomplish this. This means no DO, While or For loops In Java For example, if the user were to input “Hello”. The out put would be : olleH I’m done.
IN JAVA: Write code (using ArrayLists) to read a line of input from the user and...
IN JAVA: Write code (using ArrayLists) to read a line of input from the user and print the words of that line in sorted order, without removing duplicates. For example, the program output might look like the following: Type a message to sort: to be or not to be that is the question Your message sorted: be be is not or question that the to to
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads...
Java Program : Please save the program with the name ‘Dstring.java’ Write a program that reads a string from the keyboard. If the length of the string is an even number, your program should split the string into two strings of equal length. If the length of the string is odd, your program should split the string into two strings where the first part has one more character than the second part. Your program should output the two strings it...
Write a java program that repeatedly prompts the user to input a string starting with letters...
Write a java program that repeatedly prompts the user to input a string starting with letters from the English alphabet. The program must stop getting input when the user inputs the string “STOOOOP”. Then the program must display the words starting with each letter from the alphabet in a separate line (e.g. you need to make a new line after all words starting with a specific letter are finished.
In Coral,write a program that reads a list of 10 integers and outputs those Integers in...
In Coral,write a program that reads a list of 10 integers and outputs those Integers in Reverse. For coding Simplicity, follow each output integer by a space, including the last one. Then, output a new line. Example if the input is 2 4 6 8 10 12 14 16 18 20, the output is: 20 18 16 14 12 10 8 6 4 2 to achieve above first read the integers into an array. Then output the array in reverse
Write code in JAVA Write a program that will output a right triangle based on user...
Write code in JAVA Write a program that will output a right triangle based on user specified input height (int) and specified input symbol (char).The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches specified input height. Output a space after each user-specified character, including after the line's last user-specified character. Hint: Use a nested for loop. Ex:If the input...
Your program, called should take two command line arguments, the dictionary, and the text that you...
Your program, called should take two command line arguments, the dictionary, and the text that you wish to spellcheck. Provide some sample text. Your program should be case insensitive (so you can toLower everything). Numbers and contractions are considered valid words. You may use the java HashTable or HashMap to implement this program; but it must use some kind of hash table.
1 Design and implement FileCompare program that compares two text input files (file1.txt and file2.txt), line-by-line,...
1 Design and implement FileCompare program that compares two text input files (file1.txt and file2.txt), line-by-line, for equality. Print any lines that are not equivalent indicating the line numbers in both files. The language of implementation is java 2 . Create a program that reads a string input from the user, then determines and prints how many of each lowercase vowels (a, e. i, o, and u) appear in the entire string. Have a separate counter for each vowel. Also...