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
Elden [556K]
1 year ago
3

Many documents use a specific format for a person's name. Write a program that reads a person's name in the following format:

Computers and Technology
1 answer:
Tema [17]1 year ago
5 0

Using the knowledge in computational language in JAVA it is possible to write the code that write a program whose input is: firstName middleName lastName, and whose output is: lastName, firstName middleInitial.

<h3>Writting the code:</h3>

<em>import java.util.Scanner;</em>

<em>import java.lang.*;</em>

<em>public class LabProgram{</em>

<em>public static void main(</em><em>String</em><em>[] args) {</em>

<em>String name;</em>

<em>String lastName="";</em>

<em>String firstName="";</em>

<em>char firstInitial=' ',middleInitial=' ';</em>

<em>int counter = 0;</em>

<em>Scanner input = new Scanner(System.in);</em>

<em>name = input.nextLine(); //read full name with spaces</em>

<em>int i;</em>

<em>for(i = name.length()-1;i>=0;i--){</em>

<em>if(name.charAt(i)==' '){</em>

<em>lastName = name.</em><em>substring</em><em>(i+1,name.length()); // find last name</em>

<em>break;</em>

<em>}</em>

<em>}</em>

<em />

<em>for(i = 0;i<name.length()-1;i++){</em>

<em>if(name.charAt(i)==' '){</em>

<em>firstName = name.substring(0, i); // find firstName</em>

<em>break;</em>

<em>}</em>

<em>}</em>

<em />

<em />

<em>for(i = 0 ;i<name.length();i++){</em>

<em>if(name.charAt(i)==' '){</em>

<em>counter</em><em>++; //count entered names(first,middle,last or first last only)</em>

<em>}</em>

<em>}</em>

<em>if(counter == 2){</em>

<em>for(i = 0 ;i<name.length();i++){</em>

<em>if(Character.</em><em>toUpperCase</em><em>(name.charAt(i)) == ' '){</em>

<em>middleInitial = Character.toUpperCase(name.charAt(i+1));//find the middle name initial character</em>

<em>break;</em>

<em>}</em>

<em>}</em>

<em>}</em>

<em>firstInitial = </em><em>Character</em><em>.toUpperCase(name.charAt(0)); //the first name initial character</em>

<em>if(counter == 2){</em>

<em>System.out.print(lastName+", "+firstName+" "+</em><em>middleInitial</em><em>+".");</em>

<em />

<em>}else{</em>

<em>System.out.print(lastName+", "+firstName);</em>

<em />

<em>}</em>

<em>}</em>

<em>}</em>

See more about JAVA at brainly.com/question/12975450

#SPJ1

You might be interested in
Fifty part-time students were asked how many courses they were taking this term. The (incomplete) results are shown below. Need
Ne4ueva [31]

Answer:

The answer for B is 10% and for C is 40%.

Explanation:

To get the percentage for B you take the the frequecy of students taking 2 courses (5) and multiply it by 100 then you divide it by whole number of students.

For C you do the after adding the number of students taking 1 or 2 courses (20).

5 0
3 years ago
Write down the name of output devices
notka56 [123]

Answer:

Monitor

Printer

Headphones

Computer Speakers

Projector

GPS

Sound Card

Video card

4 0
3 years ago
Read 2 more answers
(Count the occurrences of words in a text file) Rewrite Listing 21.9 to read the text from a text file. The text file is passed
Oksanka [162]

Answer:

Explanation:

The following is written in Java. It uses File input, to get the file and read every line in the file. It adds all the lines into a variable called fullString. Then it uses regex to split the string into separate words. Finally, it maps the words into an array that counts all the words and how many times they appear. A test case has been created and the output can be seen in the attached image below. Due to technical difficulties I have added the code as a txt file below.

3 0
3 years ago
What is the utility of a lever?
Kamila [148]
Muy cosas.
 fazer una montanha russa andar,ativar una armadilha, ativar una puerta etc.
3 0
4 years ago
Read 2 more answers
. Write a function wordscramble that will receive a word in a string as an input argument. It will then randomly scramble the le
inysia [295]

Answer: You can use the function randperm() to generate a random permutation of the indexes. so then you would use the random permutation to reorder the string array

Explanation:

4 0
3 years ago
Other questions:
  • The registrar does all of the following except:
    12·2 answers
  • What is the primary benefit of using solid state storage
    7·1 answer
  • Which of the following actions has no impact on your credit score
    9·1 answer
  • Reference variables allow arguments to be passed by ____________.
    7·1 answer
  • What is microsoft certification?
    8·1 answer
  • Selective colleges choose to have in-person meetings to learn more about the applicants. These meetings are called:
    8·2 answers
  • What specific job usually includes the important pre-production step of making the
    12·1 answer
  • 1. Choose in each case that it affects which of the Information security requirements (confidentiality, integrity, availability)
    12·1 answer
  • Is hacking always wrong? Creating viruses?
    12·2 answers
  • Help me with this…… please
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!