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
ivann1987 [24]
3 years ago
14

I'm stuck on this Java exercise problem and don't know how to organize my code with proper formatting and it's not helping that

I'm pretty terrible at logic. I can't figure out how to return the number of spaces to be displayed in the main method.

Computers and Technology
1 answer:
Volgvan3 years ago
4 0

In your "count spaces method" before the for loop, you want to declare an int variable (let's call it spc)

then, each time you find that charat, spc++.


also, the string must be declared in the main method, not the spaces count method.


The actual code:


public class CountSpaces{

public static void main(String[] args){

String instring = "(your quote here)";

int spaces = calculateSpaces(instring);

System.out.println("The number of spaces is " + spaces);

}

public static int calculateSpaces(String in){

int spc = 0;

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

if(in.charAt(i)== ' '){

spc++;

}

}

return spc;

}

}


that should be it.  If you have any questions, feel free to reach out.

You might be interested in
Which social networking function came first?
amm1812

D, Online bulletin boards.


♣Amaranthine
3 0
3 years ago
Read 2 more answers
Write a constructor for BaseballPlayer. The constructor takes three int parameters: numHits, numRuns, and numRBIs storing the va
Monica [59]

Answer:

Following are the code to the given question:

public class BaseballPlayer//defining a class BaseballPlayer

{

BaseballPlayer(int numHits, int numRuns, int numRBIs)//defining a parameterized cons

{

}

}

Explanation:

Some of the data is missing, which is why the solution can be represented as follows:

In this code, a class BaseballPlayer is defined, and inside the class a parameterized constructor is defined that holds three integer variable "numHits, numRuns, and numRBIs".

5 0
3 years ago
If byte stuffing is used to transmit Data, what is the byte sequence of the frame (including framing characters)? Format answer
Lerok [7]

Answer:

Correct Answers: 01h 79h 1Bh 78h 78h 1Bh 7Ah 04

Explanation:

Solution is attached below

4 0
3 years ago
OSHA standards appear in the ___________ and are then broken down into ____________.
miskamm [114]
OSHA standards appear in the <span>Code of Federal Regulations (CFR) and are then broken down into Parts</span>
3 0
3 years ago
Which of the following items in the folder window allows users to view locations which have been visited before?
Shkiper50 [21]
Previous locations arrow
8 0
3 years ago
Other questions:
  • 61. Select an activity of the Production Phase: a. a web authoring tool is often used b. the graphics, web pages, and other comp
    10·1 answer
  • The integer variables first and last have been declared and assigned values (with last &gt;= first). Allocate an integer array t
    10·1 answer
  • A short circuit locator should be periodically run along the cords used in a shop to check for shorts and open circuits. A.)True
    12·2 answers
  • In round-robin scheduling,a) the time quantum should be larger than the context switch time. b) the time quantum should be as sm
    15·1 answer
  • 5. Drawing Conclusions If you were a person in
    10·1 answer
  • Technology will not? A. change the way work is done B. process information faster C. slow the pace of work D. link companies and
    8·1 answer
  • Match the file extensions to the file types. Some file types may be used more than once.
    11·1 answer
  • You are an ISP. For the Address Block 195.200.0.0/16 a. If you have 320 Customers that need 128 addresses/customer - will there
    6·1 answer
  • How are gems and precious metals similar?
    6·2 answers
  • PLEASE HELP THIS IS CONFUSING ME
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!