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
yuradex [85]
3 years ago
7

Write code (ReverseNames.java) that prompts the user to enter his or her full name, then prints the name in reverse order (i.e.,

last name, first name). You may assume that only a first and last name will be given. Here is a sample dialogue with the user:

Engineering
1 answer:
yan [13]3 years ago
5 0

Answer:

import java.util.Scanner;

import java.io.*;

public class Main{

    public static void main(String []args){

       

       StringBuilder reversedName = new StringBuilder();

       StringBuilder subName = new StringBuilder();

       

       Scanner myObj = new Scanner(System.in);  // Create a Scanner object

       System.out.println("Enter your full name (last name + first name)");

   

       String name = myObj.nextLine();  // Read user input

       

       for (int i = 0; i < name.length(); i++) {

           

           char currentChar = name.charAt(i);

           

           if (currentChar != ' ') {

               subName.append(currentChar);

           } else {

               reversedName.insert(0, currentChar + subName.toString());

               subName.setLength(0);

           }

       }

       String Resul = reversedName.insert(0, subName.toString()).toString();

       System.out.println("Reverse full name: " + Resul);

    }

}

Explanation:

To solve the problem we used StringBuilder, that allow us to build a string letter by letter, we are using two, one to store temporary information (subName) and the other to store the surname plus name (reversedName). After defining the variables, the program asks for the user fullname using Scanner class and it's method .nextLine (the variable 'name' will save the user input). A while loop is also used to iterate over the name, taking character by character with the method .charAt, the program will append letters in subName until it finds a space only then the content of subName will be transfer to reversedName and the content of subName will be deleted, then the program continues with the process until the end of the for loop; finally, the program places the content of subName at the beginning of reversedName, and print the result transforming the StringBuilder to a normal string.

You might be interested in
an electric circuit includes a voltage source and two resistances (50 and 75) in parallel. determine the voltage source required
ASHA 777 [7]

Answer:

The voltage source required to provide 1.6 A of current through the 75 ohm resistance is 120 V.

Explanation:

Given;

Resistance, R₁ = 50Ω

Resistance, R₂ = 75Ω

Total resistance, R = (R₁R₂)/(R₁ + R₂)

Total resistance, R = (50 x 75)/(125)

Total resistance, R = 30 Ω

According to ohms law, sum of current in a parallel circuit is given as

I = I₁ + I₂

I = \frac{V}{R_1} + \frac{V}{R_2}

Voltage across each resistor is the same

1.6 = \frac{V}{R_2}  

V = 1.6 x R₂

V = 1.6 x 75

V = 120 V

Therefore, the voltage source required to provide 1.6 A of current through the 75 ohm resistance is 120 V.

This voltage is also the same for 50 ohms resistance but the current will be 2.4 A.

3 0
3 years ago
Read 2 more answers
Uses of P-N junction
Lubov Fominskaja [6]

Answer:

Explanation:

Two that come to mind:

  1. a semiconductor diode is essentially a PN junction
  2. a transistor is made of two pn junctions.
4 0
3 years ago
Select the correct answer. Ruby wants to create a cube puzzle game. For that she has to create a cube. Which drafting tool do yo
Alexxx [7]

Answer:

D. a triangle and a T-Square

Explanation:

A T-Square is the best drawing tool to create squares. You would need a squares to create cubes.

3 0
3 years ago
A metal crystallizes with a face-centered cubic lattice. The edge of the unit cell is 408 pm. Calculate the number of atoms in t
uysha [10]

Answer:288 pm

Explanation:

Number of atoms(s) for face centered unit cell -

Lattice points: at corners and face centers of unit cell.

For face centered cubic (FCC), z=4.

- whereas

For an FCC lattices √2a =4r =2d

Therefore d = a/√2a = 408pm/√2a= 288pm

I think with this step by step procedure the, the answer was clearly stated.

8 0
3 years ago
Who knows about welding ??
shtirl [24]
They joint together melting metal
5 0
4 years ago
Other questions:
  • What are the basic types of heat exchangers?
    9·1 answer
  • The hoist of a crane consists of a 10 kW electric motor running at 1440 rpm drivine 300 mm diameter drunn through a 60:1 gear re
    13·1 answer
  • Water is the working fluid in an ideal Rankine cycle. Saturated vapor enters the turbine at 12 MPa, and the condenser pressure i
    8·2 answers
  • I got a rubber band car assigned as a project today. The goal is for the car to go farther/faster than the car my teacher is mak
    6·1 answer
  • Air at 80 °F is to flow through a 72 ft diameter pipe at an average velocity of 34 ft/s . What diameter pipe should be used to
    10·2 answers
  • A closed rigid tank contains water initially at 10,000 kPa and 520ºC and is cooled to a final temperature of 270° C. Determine t
    9·1 answer
  • When you receive a vertical promotion, you are more likely to _______ than when you receive a horizontal promotion. a. Deal with
    9·1 answer
  • What is the safe psi pressure for acetylene
    13·1 answer
  • Paragraph about Mercedes jellinek
    14·1 answer
  • When a technician is ohming out a load in a circuit, what reading should the technician get if the load is good
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!