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
Afina-wow [57]
3 years ago
7

Write a Java method that will take a string and reverse it. Can you come up with a method that is faster than regular reversing

of the for loop? [10 points] Example #1: Input: ‘Hello World’ Output: ‘dlroW olleH’
Computers and Technology
1 answer:
rewona [7]3 years ago
3 0

Answer:

The program to this question as follows:

Program:

import java.util.*; //import package

class Main //defining class  Main

{

public static void main(String[] as) //defining main method

{

String input_string, input; //defining string variables

Scanner obz=new Scanner(System.in); //creating scanner class object

System.out.println("Input the string value:   "); //print message

input_string=obz.nextLine(); //input value by user

input=new StringBuffer(input_string).reverse().toString(); //creating instance variable with using reverse method

System.out.print(input);//print value    

}

}

Output:

Input the string value:  

Hello World

dlroW olleH

Explanation:

In the above program code, a class Main is defined, inside this class-main function is declared, inside this function two string variable "input_string and input" are defined, in which the "input_string" variable is used to take input from the user side.

  • The input variable used as an instance variable, that uses StringBuffer, reverse, and toString method.
  • The StringBuffer accepts the "input_string" variable as parameter and toString, reverse method is used to convert all value into a string and reverse method convert value in reverse order. In the last, the print function is used that print input variable value.
You might be interested in
I need help with Exercise 3.6.7: Sporting Goods Shop in CodeHS. ASAP
attashe74 [19]

Answer:

OK

Explanation:

7 0
3 years ago
What's the problem with this code ?
Svet_ta [14]
Hi,

I changed your program using some of the concepts you were trying to use. Hopefully you can see how it works:

#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
   short T;
   cin >> T;
   cin.ignore();

   string str[100];

   for(int i=0; i<T; i++)
   {
      getline(cin, str[i]);
   }

   for (int i = 0; i < T; i++)
   {
      stringstream ss(str[i]);
      string tmp;
      vector<string> v;

      while (ss >> tmp)
      {
          // Let's capitalize it before storing in the vector
          if (!tmp.empty())
          {
              transform(begin(tmp), end(tmp), std::begin(tmp), ::tolower);
              tmp[0] = toupper(tmp[0]);
           }
           v.push_back(tmp);
        }

        if (v.size() == 1)
        {
           cout << v[0] << endl;
        }
        else if (v.size() == 2)
        {
           cout << v[0][0] << ". "  << v[1] << endl;
        }
        else
        {
            cout << v[0][0] << ". " << v[1][0] << ". " << v[2] << endl;
        }
    }

     return 0;
}

4 0
3 years ago
Which characteristics describe the WMV video file format? Choose all that apply.
Lelechka [254]

Answer:

the answer is A, B, C hope this helps.

8 0
2 years ago
Create an unambiguous grammar which generates basic mathematical expressions (using numbers and the four operators +, -, *, /).
Anastasy [175]

Answer:

Explanation:

Let G denote an unambiguous Grammar capable of producing simple mathematical expressions, involving operators +,-,*,/. These operators are left associative (which ensures left to right evaluation). S is the start symbol of the Grammar i.e. the production starts from S. n denotes a number and is a terminal i.e. we can't produce anything further from n. Then, the solution is as follows :

S → S + T |S - T | S

T→T | F | T*F|F

F → n

Here, S, T and F are variables. Note that /,* have been given precedence over +,-.

8 0
3 years ago
The ____number system is base 10​
evablogger [386]

Answer:

The correct answer to this question is given below in the explanation section.

Explanation:

This is a fill-in-blank question.

The answer is:

The decimal number system is base 10.

In our everyday life, we use a number system that is a Base-10 system. As we know that the base-10 is known as the decimal system and this number has 10 digital starting from 0 to 9 such as:

0,1,2,3,4,5,6,7,8,9

We use this number system in our daily accounting and in daily life and it is a base-10 number system. This number system uses 10 as its base number so it is called a base-10 system. It is also called the decimal number system.

7 0
3 years ago
Other questions:
  • 4. An outline is most like which of the following? (1 point)
    14·1 answer
  • Word processing, presentation, photo editing, and video games are all types of what?
    9·2 answers
  • The IT department sent out a memo stating that it will start delivering desktop computer interfaces through the IT data center v
    5·1 answer
  • When storing used oil, it needs to be kept in ___________ containers.
    12·1 answer
  • How is counting in this circle and square system similar to how we count in our regular lives? How is it different?
    15·1 answer
  • A CPU has 32 KB cache, 2-way set associative, 16-byte block size. How many bits are required to use index each set in this cache
    6·1 answer
  • Ten members of a wedding party are lining up in a row for a photograph.
    8·1 answer
  • Ohanians “great big secret” is that:
    8·1 answer
  • HELP PLEASE!!!! Which type of prototyping is most often associated with the rapid prototyping development method?
    11·1 answer
  • Pls help I will mark you the brainliest
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!