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
mestny [16]
3 years ago
10

Write a method that accepts a String object as an argument and displays its contents backward. For instance, if the string argum

ent 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.
Computers and Technology
1 answer:
Nata [24]3 years ago
6 0

Answer:

// importing the necessary libraries

import java.util.Scanner;

public class BackwardString {

public static void main(String[] args) {

String input;

// Scanner object to read string from user input

Scanner scanner = new Scanner(System.in);

System.out.print("Enter String here : ");

input=scanner.next();

// calling backward method to reverse passed string

backward(input);

// closing Scanner object

scanner.close();

}

// Method to Reverse the input string

private static void backward(String source) {

int i, len = source.length();

StringBuilder dest = new StringBuilder(len);

for (i = (len - 1); i >= 0; i--){

dest.append(source.charAt(i));

}

System.out.println("Reversed String : "+dest);

}

}

Explanation:

// importing the necessary libraries

import java.util.Scanner;

public class BackwardString {

public static void main(String[] args) {

String input;

// Scanner object to read string from user input

Scanner scanner = new Scanner(System.in);

System.out.print("Enter String here : ");

input=scanner.next();

// calling backward method to reverse passed string

backward(input);

// closing Scanner object

scanner.close();

}

// Method to Reverse the input string

private static void backward(String source) {

int i, len = source.length();

StringBuilder dest = new StringBuilder(len);

for (i = (len - 1); i >= 0; i--){

dest.append(source.charAt(i));

}

System.out.println("Reversed String : "+dest);

}

}

The program above accepts a String object as an argument and displays its contents backward.

It reverses the any string inputed while producing the output.

You might be interested in
Which words in the sentence make up the adjective phrase? Which word does the adjective phrase modify? The farmer delivers five
jasenka [17]
B....."........."........"...
6 0
3 years ago
All of the following are types of data storage devices except CD/DVD computer monitor digital cameras flash drive
horrorfan [7]

Computer Monitors are not storage devices.

3 0
3 years ago
In which way is a copper cable related to a wireless transmission
Citrus2011 [14]

Answer: whats the answer choices

Explanation:

4 0
3 years ago
Blank are what make up the World Wide Web.
andreyandreev [35.5K]
Web pages make this up.
3 0
3 years ago
How to build aeroplain pls tell me I want to go to amereeca
damaskus [11]

Answer:

lol i think it would be cheaper to but a ticket or drive there

8 0
3 years ago
Other questions:
  • Provide an example of a time in your personal or work life when you used the household measuring system and measured out an exac
    6·1 answer
  • 1. Which of the following options will allow you to insert a quick table? (1 point) Insert ribbon > Shapes drop-down menu
    6·2 answers
  • Your friends know that you understand a lot about computers, both the technical details of how they operate as well as informati
    12·1 answer
  • One common method of converting symbols into binary digits for computer processing is called ASCII​ (American Standard Code of I
    5·1 answer
  • On his computer desktop, Rodney can see several different files, each immediately accessible. Because he is actively working on
    13·1 answer
  • ---------------is a systematic review of a person’swork and achievements over a recent period, usually leading toplans for the f
    11·1 answer
  • What is the major difference between the intranet and extranet?
    11·1 answer
  • Which data type is -7
    13·1 answer
  • Which of these commands is found by default on the quick access toolbar 1)save 2)new 3)open 4)print
    10·1 answer
  • After a group sets a project schedule, members should be prepared to
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!