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.

I'm Stuck On This Java Exercise Problem And Don't Know How To Organize My Code With Proper Formatting

Answers

Answer 1

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.


Related Questions

what is the first thing you should do when troubleshooting a computer problem

Answers

Final answer:

The first step in troubleshooting a computer problem is to identify the issue clearly by noting symptoms, contexts, and error messages. This forms the basis for applying problem-solving strategies to address the problem effectively.

Explanation:

The first thing you should do when troubleshooting a computer problem is to identify the issue. This involves observing the symptoms of the problem, understanding the context in which it occurs, and gathering any error messages that might be displayed. Once you have a clear understanding of the issue, you can then proceed to apply different problem-solving strategies. In some cases, a simple restart might be the solution, but for more complex problems, you might need to research the issue, consult technical forums, or seek professional help.

Steps for problem-solving include:


 Identify the "given" information that you have about the problem, such as error messages or what you were doing when the problem occurred.
 Determine what the problem is asking you to "find" or resolve.
 Apply a suitable troubleshooting strategy based on the information collected.

Final answer:

The first step in troubleshooting a computer problem is to clearly identify the issue by gathering information on symptoms, error messages, and system behavior. The next steps involve determining the 'given' information and what is needed to find a solution. Documenting all actions taken during the process is important for efficiency and future reference.

Explanation:

Initial Steps in Troubleshooting a Computer Problem

When troubleshooting a computer problem, the first strategy is to clearly identify the issue at hand. This involves gathering information about the symptoms of the problem, any error messages, and understanding what the computer was doing when the problem occurred. Once the issue is identified, you can move forward with appropriate troubleshooting steps, comparing your problem to known issues, or using specialized tools for diagnosis.

During the troubleshooting process, it is essential to identify the 'given' information, such as any error messages, system behavior, and recent changes to the computer system. You should then determine what the problem is asking you to 'find', which may include restoring functionality, determining the cause of an error, or rectifying a performance issue. By clearly outlining the problem and gathering all the necessary information, you can systematically approach the troubleshooting process and apply various problem-solving strategies to find a solution.

It is crucial to approach the problem systematically and remain organized throughout the process. Documenting each step taken can help avoid repeating actions and create a record for future reference, fostering efficient and effective troubleshooting.

Other Questions
Describe Solomon Sachs study How do you think you would have responded to tbs study if you were a part of it What is the pH of a solution with a concentration of 3.6 10-5 molar H3O+? Show, or explain, the work used to solve this problem. In 150 words summarize what you know about preventing cross-contamination WILL NAME BRAINEST!how did Edgar Allan Poe effect American literature? John says the transformation rule (x, y) > (x + 4, y + 7) can be used to describe the slide of the pre-image (4, 5) to the image (0, 2). What was his error? Who benefits and who suffers most from a centrally planned economy? Choose the answer that best matches the word in italics. Use context clues to determine the meaning of the word, if necessary She examined my costume minutely before declaring it the winner..with close attention to even the smallest details.for a minute.piece by piece, minute by minute.casually Mesopotamia was bordered on the south by which body of water? what late nineteenth century government believed that it had contributed remarkable achievements, inventions, and innovations to the world and had no reason to imitate foreigners?a. franceb. chinac. united statesd. japan reflectingWhich segment is a reflection of segment AB over the line x = 1? Describe the use of omens in Books 13-18 of The Odyssey. What is the significance of the omens in this part of the story? Need help with number 4 quick please. Two masses exerting a force on each other is an example of________ A.) Kepler's law B.)Heliocentric theory C.)Universal law of gravitation D.)Geocentric theory Which expression is equivalent to 2/7k(k-7)? Assume k=0.A. 2/7-k,B. 2/7-2/k,C. 2k/7-7,D. 2k/7k-2k Use the identity a^3+b^3=(a+b)^33ab(a+b) to determine the sum of the cubes of two numbers if the sum of the two numbers is 4 and the product of the two numbers is 1. This section of a page from a telephone directory shows a column of 11 names in 1 inch. Each page has four 10-inch columns. Write an algebraic expression for the approximate number of names in p pages of the directory. Is Christadelphianism Christian? A population of frogs inhabits a lake. If the resource availability of the lake changes, the population may to use the resources that are available. As a result, the population would exhibit . Escoge la palabra que completa la oracin siguiente.Javier ___________ en clase a veces. Necesita _________ ms temprano.Te duermes, te acostasSe duerme, acostarseDormirme, acuestasteLes duerme, acostarseloEscoge la traduccin correcta con los pronombres.Im going to cook the hamburgers for them.Les las voy a cocinar.CocinoslosVoy a cocinarmelosVoy a cocinrselasEscoge la repuesta correcta con el pronombre.Tienes mi libro?S, me tengoS, lo tengoS, me lo tengoS, las tengoEscoge la repuesta correcta con el pronombre.Qu vas a comprar para la fiesta de Anna?Voy a darle un anillo.Voy a darme un anilloLa voy a dar un anillo.Voy a darte un anillo.Escoge la repuesta correcta con el pronombre.Cundo recibiste tu carro nuevo?Mis padres lo dieron me ayer.Mis padres me lo dieron ayer.Mis padres se lo dieronme ayer.Mis padres se me dieron ayer.Escoge la palabra que completa la oracin siguiente.Son los zapatos de t y Maria. Los zapatos son ____SuyoSuyosNuestroNuestros Hugo polled 100 randomly selected people to see if they had exercised that week and found that 85% said they had. Lily asked 400 randomly selected people the same question and found that 85% of them also responded that they had exercised that week. If Hugo and Lily use a 99% confidence level (z*score of 2.58), which statement is true? E = z* - Hugos margin of error will be exactly 2 times as large as Lilys margin of error. - Lilys margin of error will be exactly 2 times as large as Hugos margin of error. - Hugos margin of error will be exactly 4 times as large as Lilys margin of error. - Lilys margin of error will be exactly 4 times as large as Hugos margin of error.