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
zlopas [31]
3 years ago
11

What output is produced by the following program segment? Why? (Recall that name.charAt(i) is the i-th character in the string,

name.)
String name;
int i;
boolean startWord;

name = "Richard M. Nixon";
startWord = true;
for (i = 0; i < name.length(); i++) {
if (startWord)
System.out.println(name.charAt(i));
if (name.charAt(i) == ' ')
startWord = true;
else
startWord = false;
}
Computers and Technology
1 answer:
vekshin13 years ago
8 0

Answer:

The output is:

R

M

N

Explanation:

The code snippet print the beginning letter of each word in the given name.

In the for loop snippet:

first the program check if startWord is true and it is true, then it print the value of the character at index 0. Then it check if value of character is empty. If it is empty, startWord is initialized to true else it is initialized to false.

The loop only print a character when the value of i are 0, 8 and 11 which are also the beginning character of a word.

You might be interested in
Difference between switch case and if else statement.​
ser-zykov [4K]

Answer:

<h3><em>SWITCH</em><em> </em><em>CASE</em><em>:</em></h3>

<em>☆</em><em> </em><em>STATEMENT</em><em> </em><em>WILL</em><em> </em><em>BE</em><em> </em><em>EXECUTED</em><em> </em><em>IS</em><em> </em><em>DECIDED</em><em> </em><em>BY</em><em> </em><em>USER</em><em>. </em>

<em>☆</em><em> </em><em>SWITCH</em><em> </em><em>STATEMENT</em><em> </em><em>EVALUATES</em><em> </em><em>ONLY</em><em> </em><em>CHARACTER</em><em> </em><em>《</em><em>OR</em><em> </em><em>》</em><em>INTEGER</em><em> </em><em>VALUE</em><em>. </em>

<em>☆</em><em> </em><em>IT</em><em> </em><em>USING</em><em> </em><em>SINGLE</em><em> </em><em>EXPRESSION</em><em> </em><em>FOR</em><em> </em><em>MULTIPLE</em><em> </em><em>CHOICES</em><em>. </em>

<h3><em>IF</em><em> </em><em>-</em><em> </em><em>ELSE</em><em> </em><em>STATEMENT</em><em>. </em></h3>

<em>☆</em><em> </em><em>STATEMENT</em><em> </em><em>WILL</em><em> </em><em>BE</em><em> </em><em>EXECUTED</em><em> </em><em>DEPEND</em><em> </em><em>UPON</em><em> </em><em>THE</em><em> </em><em>OUTPUT</em><em> </em><em>OF</em><em> </em><em>THE</em><em> </em><em>EXPRESSION</em><em> </em><em>INSIDE</em><em>. </em>

<em>☆</em><em> </em><em>IF</em><em> </em><em>THE</em><em> </em><em>STATEMENT</em><em> </em><em>EVALUATES</em><em> </em><em>INTEGER</em><em>, </em><em>CHARACTER</em><em>, </em><em>POINTER</em><em>《</em><em> </em><em>OR</em><em> </em><em>》</em><em>FLOATING-</em><em> </em><em>POINT</em><em> </em><em>TYPE</em><em> </em><em>《</em><em> </em><em>OR</em><em> </em><em>》</em><em>BOOLEAN</em><em> </em><em>TYPE</em><em>. </em>

<em>☆</em><em> </em><em>IF</em><em> </em><em>USING</em><em> </em><em>MULTIPLE</em><em> </em><em>STATEMENT</em><em> </em><em>FOR</em><em> </em><em>MULTIPLE</em><em> </em><em>CHOICES</em><em>. </em>

<em>HOPE</em><em> </em><em>IT</em><em> </em><em>HELP</em><em>.</em><em>.</em><em>.</em><em>.</em><em /><em /><em />

7 0
2 years ago
Why is code tracing important when debugging?
larisa [96]

It helps reveal the flow of execution of your program, including results of in-between evaluations. In other words, you can see what your program is doing, and why it takes the decisions it is taking.

If something unexpected happens, the trace will show you the sequence of events that lead to it.

7 0
3 years ago
public class N extends String, Integer { } When you compile, you get the following message: N.java:1: ‘{‘ expected public class
GREYUIT [131]

Correct Question:

Public class N extends String, Integer { } When you compile, you get the following message: N.java:1: ‘{‘ expected public class N extends String, Integer ^ 1 error Explain what the problem is and how to fix it.

Note the capital letter P

Answer and Explanation:

Problem: This is a syntax error, the key word "public" should begin with a small letter and not capital letter.

How to fix: Replace the capital letter P by  small letter p and recompile.

8 0
2 years ago
The timer is running in the up mode with a period of 800 cycles. Channel 1 engages the output mode (Set/Reset) and sets its regi
Soloha48 [4]

Answer:

Explanation:

Part a)

_______________ ____________ _____________ ___

TAR | /\ \/ /\ \/ /\

|//////////|____________|____________|_____________|__________|

0 600 800 600 800 600

PWM Duty Cycle = 200/800 = 25%

Part b)  

______________ _________________ _________ _________________

TAR | \/ /\ \/ /\ \/

|//////////|_________|_________________|__________| _______________|

0 600 800 600 800 600

PWM Duty Cycle = 600/800 = 75%

7 0
3 years ago
How to make a conversation program in java
Talja [164]

Answer:

Creating a Chat Server Using Java

Introduction: Creating a Chat Server Using Java. ...

Step 1: Setup a ServerSocket in the Server Class. ...

Step 2: Create a Socket in the Login Class. ...

Step 3: Create a Loop to Continuously Accept Clients. ...

Step 4: Create the Client Threads. ...

Step 5: Create the Server Thread. ...

Step 6: Make the Client Thread Send and Receive Data.

4 0
3 years ago
Other questions:
  • A(n) _____ measures the ability to juggle a variety of demands, as in a manager's job where the candidate is presented with simu
    8·1 answer
  • When a user inserts a PivotTable, where will it be inserted?
    15·1 answer
  • This isn't a homework question but rather a technological problem. I connected my device to the motherboard but it will not dete
    5·2 answers
  • . Suppose that name is a variable of type string. Write the input statement to read and store the input Brenda Clinton in name
    5·1 answer
  • Suppose a MATV/SMATV (Satellite Master Antenna Television) firm has to start it's operation in the metropolitan area of a countr
    12·1 answer
  • What layer in the Transmission Control Protocol/Internet Protocol (TCP/IP) model is responsible for defining a way to interpret
    11·1 answer
  • What is the penalty for violating section 1201 of title 17 chapter 21 of the us code
    15·1 answer
  • What is the main difference between project tasks and client support tickets?
    11·1 answer
  • Which of the following is not part of the processes involved in data valida
    11·1 answer
  • Which of the following are picture adjustments that can be made to images?
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!