Question

This application accepts user input from the console and then prints the reverse of the user...

This application accepts user input from the console and then prints the reverse of the user input to the console. The last string that this program should print is the reverse user input.

JAVA

Homework Answers

Answer #1

Solution:

import java.lang.*;
import java.io.*;
import java.util.*;

public class Main {
   public static void main(String[] args)
   {
  
//standerd input stream
   Scanner sc= new Scanner(System.in);

//taking string as input
       String st = sc.nextLine();

       // converting string to string buffer
       StringBuffer s = new StringBuffer(st);
  
//reverse() reverses the string
       s.reverse();
      
//printing the reversed string
       System.out.println(s);
   }
}

Note: If you find any error in the above code it may be due to different name of file , so please save your file with name Main.java

If you find my answer helpful,please give thumbs up

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
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 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
Write a method that accepts a String object as an argument and displays its contents backward....
Write a method that accepts a String object as an argument and displays its contents backward. For instance, if the string argument is "gravity" the method should display "ytivarg". Demonstrate the method in a program that asks the user to input a string and then prints out the result of passing the string into the method. Sample Run java BackwardString Enter·a·string:Hello·world↵ dlrow·olleH↵
problem 1 Write a program that asks the user for an integer and then prints out...
problem 1 Write a program that asks the user for an integer and then prints out all its factors. For example, when the user enters 84, the program should print 2 2 3 7 Validate the input to make sure that it is not a character or a string using do loop. in c plus plus
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input and output with the Java console. Setup: Create a class called ConsolePractice with a main method. Create a static field in your class that stores a scanner object. You will use this scanner for all user input. private static Scanner scanner = new Scanner(System.in); Part A: Create a static method called “divide”. Your method should do the following: Accept two integers as parameters, a...
THIS QUESTION HAS TWO PARTS: A) Write an application that accepts three Strings from the user...
THIS QUESTION HAS TWO PARTS: A) Write an application that accepts three Strings from the user and displays one of two messages depending on whether the user entered the Strings in alphabetical order without regard to case. Save the file as Alphabetize.java. B) Write an application that accepts three Strings from the user and displays them in alphabetical order without regard to case. Save the file as Alphabetize2.java
write a MIPS assembly program to get an integer input from the user and multiply it...
write a MIPS assembly program to get an integer input from the user and multiply it by 2 and print output to the console
This phyton program requires you to accept from the user a three-digit integer (100-999), and prints...
This phyton program requires you to accept from the user a three-digit integer (100-999), and prints the reverse of that integer. You can assume that the input is an integer, but should not assume it's in the right range. If it's not in the right range, print "Illegal input:" and the number. Here are three sample runs: Enter a three digit decimal integer: 234 The number in reverse is: 432 Enter a three digit decimal integer: 1345 Illegal input: 1345...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
with C# create a console application that asks the user for two numbers in the range...
with C# create a console application that asks the user for two numbers in the range 0-255 and then divides the first number by the second: Enter a number between 0 and 255: 100 Enter another number between 0 and 255: 8 100 divided by 8 is 12 Enter a number between 0 and 255: apples Enter another number between 0 and 255: bananas FormatException: Input string was not in a correct format.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT