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 of the following is not a type of bank? A.Credit Union B.Online Bank C.Payday Lender D.Retail Bank
Damm [24]
C. a payday lender is a type of loan
7 0
3 years ago
Suppose that sales is a two-dimensional array of 10 rows and 7 columns wherein each component is of the type int , and sum and j
Deffense [45]

According to the given question, sales is a two-dimensional array and contains 10 rows and 7 columns wherein each component is of type integer and the variables sum and j are also of integer type.

<u>Explanation:</u>

In order to find the sum of the elements of the fifth row of sales, the correct piece of code should be:

sum=0;

for(j=0;j<7;j++)

sum=sum+sales[4][j];  

The indexing in an array always starts from zero, therefore, to calculate the sum of the fifth row, the user has to write 4 in the index to point to the fifth row.

3 0
3 years ago
When introducing a database into an organization, the database approach creates a more controlled and structured information flo
Karolina [17]

Answer:

a.cultural

Explanation:

Cultural impact generally refers to resistance to change in DBMS.It msu be assessed carefully. The Database management system is likely to have effect on functions,people and interactions.For example:- New roles might be given to already existing persons,new people might be hired.

8 0
3 years ago
SSDS are ______ than magnetic hard disks
Deffense [45]
The answer is 1 faster
6 0
2 years ago
Which branch of science helps avoid or minimize stress-related injuries at workplace
dybincka [34]

The answer is : Ergonomics .   It is about ensuring that the work system is favorable to good performance and work effectiveness and consequently,  that the work environment is compatible with the health, safety and comfort of the worker.  It reduces hazards in the working environment.

8 0
3 years ago
Other questions:
  • How to copy and paste using keyboard onchromebook?
    11·1 answer
  • Which statement describes borders and shading ?
    13·1 answer
  • Timeliness is an important goal of any access control monitoring system.<br> A. True<br> B. False
    9·1 answer
  • you are concerned with security at your company and want to implement a technology that requires no configuring on the users sid
    15·1 answer
  • Give your definition of a view. Based on the Academic Database, identify and describe a scenario where it would be necessary to
    10·1 answer
  • What is a quasi vpn?
    14·1 answer
  • Let x = ["Red", 2.55,"Green", 3,"Black","false"], then solve the following:
    7·1 answer
  • Read two numbers from user input. Then, print the sum of those numbers. Hint - Copy/paste the following code, then just type cod
    9·1 answer
  • Wyatt has a database to keep track of his enormous collection of videos. How can Wyatt find the details for the game Lost on Mar
    11·2 answers
  • Select the correct technical term for each definition by using the drop-down menus.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!