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 need to be assessed during unit testing?
diamong [38]
E) both C and D Erro handling and execution paths
8 0
3 years ago
Heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelp plz
Tanya [424]

Answer:

i wish i could help you

Explanation:

i wish i could help you

6 0
3 years ago
1. An integer in C (int) is represented by 4 bytes (1 byte = 8 bits). Find the largest integer that can be handled by C. Verify
faust18 [17]

Answer:

Check the explanation

Explanation:

In C, int requires 4 butes to sotre a integer number. that means it requires 4*8 = 32 bits. The maximum number can be stored using 32 bits is

(11111111111111111111111111111111)_2

The first digit is used for sign. decimal equivalent to this number can be computed as

(1111111111111111111111111111111)_2= 1\times2^{30}+1\times2^{29}+...+1\times2^0

=1\times2^{31}-1

= 2147483647-1=2147483646

That means int can store a up to 2147483646.

                      Testing with C code

#include<stdio.h>

int main()

{

  int a = 2147483647; // a with max number

  printf("%d\n",a);// printing max number

  a = a+1;// adding one to the number

  printf("%d\n",a);// printing the number after adding one

  return 0;

}

                THE OUTPUT

$ ./a.out

2147483647

-2147483648

4 0
4 years ago
A _______ is a hierarchical list of folders that shows the arrangement of data stored on a windows computer.
olasank [31]

A directory tree is a hierarchy of directories that consists of a single directory, called the parent directory or top level directory, and all levels of its subdirectories (i.e., directories within it).

For more information :)
http://www.linfo.org/directory_tree.html
4 0
3 years ago
Please help!!!
Leona [35]

Answer:

C. Forms often provide special tools such as drop-down boxes for finding data.

Explanation:

3 0
3 years ago
Other questions:
  • Your company is developing a new marketing campaign and wants to know which customers have never placed an order. You will need
    10·1 answer
  • Due largely to the prevalence of reading them on screens rather than in​ print, the body text of most contemporary documents now
    8·1 answer
  • Catherine wants to search online for fruit juices. She is fine with aerated or fresh fruit juices. Which Boolean operator will e
    12·2 answers
  • What is the advantage of using a high-level language over machine language for writing computer programs?
    12·2 answers
  • Please Help!
    6·2 answers
  • If you want an app to reach the largest possible audience, which two platforms should you use?
    10·1 answer
  • Which statement best describes the difference between a spreadsheet and a database?
    9·2 answers
  • What is food technology​
    5·1 answer
  • What is a limitation of 5G mmWave, despite its high speed?
    11·1 answer
  • Task 04
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!