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
Within a word processing program, predesigned files that have layout and some page elements already completed are called
dexar [7]

Answer:

I think it's B) templates

     

                   Sorry if it's wrong I'm not sure!!

Explanation:

4 0
3 years ago
Anthony is deciding between different savings accounts at his bank. He has four options, based on how frequently interest compou
anastassius [24]
He should pick the most reliable one.

Hope this helps.

4 0
3 years ago
Advantages of machine language​
morpeh [17]

Machine Language is a language used to communicate with the Central Processing Unit (also known as the CPU)

6 0
3 years ago
Critical Thinking Questions Case 7-1 ​ You recently started working part-time in a retail store, and are learning about the read
DerKrebs [107]

Answer: Laser Beams

Explanation:

  The laser beam is one of the type of technology that helps in amplifying the light by using the laser principle Stimulated emission in the laser. The word "LASER" is stand for the Light amplification by stimulated emission of radiation.  

The laser is one of the device that emitted the coherent light in the form of beam rays that is propagate only in one direction. The following are the laser beam technology are as follows:

  • Bar code reader
  • Laser surface modification  
  • Information processing
  • Laser range  

Therefore, Laser beam is the correct answer.

6 0
3 years ago
What is the purpose of the green flag in the Scratch interface?
Len [333]

Answer:

C. It begins the program.

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Which of the following is not an example of technological progress? A: new scientific knowledge that has practical applications
    12·2 answers
  • Exceptions can be handled in all of these ways except:
    6·1 answer
  • Read the excerpt from The Code Book. Other attacks include the use of viruses and Trojan horses. Eve might design a virus that i
    13·1 answer
  • How do i install windows 7 on virtual machine?​
    9·1 answer
  • WILL GIVE BRAINLIEST!!!!!!!
    9·1 answer
  • B. List any four major drawbacks of the first generation computer​
    10·1 answer
  • Picture question please help me
    8·2 answers
  • A system analyst generally needs to have a number of skills. For example, technical and analytical skills are required for this
    7·1 answer
  • What are variables in Q Basic programs​
    14·1 answer
  • What is meant by editing a document​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!