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
Wewaii [24]
3 years ago
8

Java - Using a method, how do I "write a program whose input is a character and a string, and whose output indicates the number

of times the character appears in the string. Your program must define and call the following method that returns the number of times the input character appears in the input string.
public static int countCharacters(char userChar, String userString)"

So far I have the following:
import java.util.Scanner;

public class LabProgram {

public static int countCharacters(char userChar, String userString)
{
// Create an object of the Scanner class to allow for user inputs
Scanner input = new Scanner(System.in);

// Store text in a variable
userString = input.nextLine();

// Store character in a char variable
userChar = input.next().charAt(0);

// Create and initialize a variable count to zero
// count will hold the number of occurrences of the character in the phrase
int count = 0;

// Loop through each of the character in the string text
// At every cycle of the loop, compare the character of the string
// with the character to be checked.
// If they match, count is incremented
for (int i = 0; i < userString.length(); i++) {
if (userString.charAt(i) == userChar) {
count++;
}

}

// Print out the number of occurrences due to count
System.out.println(userChar + " appears this many times " + count);
}

public static void main(String[] args) {
countCharacters(userChar, userString);
}

}
and my error is that I can't get it to run on main / I don't know where everything goes. I found the code somewhere and I've tried modifying it.
Computers and Technology
1 answer:
Ksju [112]3 years ago
6 0

Answer:Java - Using a method, how do I "write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Y"

Explanation:

You might be interested in
Given six memory partitions of 100 MB, 170 MB, 40 MB, 205 MB, 300 MB, and 185 MB (in order), how would the first-fit, best-fit,
nlexa [21]

Answer:

We have six memory partitions, let label them:

100MB (F1), 170MB (F2), 40MB (F3), 205MB (F4), 300MB (F5) and 185MB (F6).

We also have six processes, let label them:

200MB (P1), 15MB (P2), 185MB (P3), 75MB (P4), 175MB (P5) and 80MB (P6).

Using First-fit

  1. P1 will be allocated to F4. Therefore, F4 will have a remaining space of 5MB from (205 - 200).
  2. P2 will be allocated to F1. Therefore, F1 will have a remaining space of 85MB from (100 - 15).
  3. P3 will be allocated F5. Therefore, F5 will have a remaining space of 115MB from (300 - 185).
  4. P4 will be allocated to the remaining space of F1. Since F1 has a remaining space of 85MB, if P4 is assigned there, the remaining space of F1 will be 10MB from (85 - 75).
  5. P5 will be allocated to F6. Therefore, F6 will have a remaining space of 10MB from (185 - 175).
  6. P6 will be allocated to F2. Therefore, F2 will have a remaining space of 90MB from (170 - 80).

The remaining free space while using First-fit include: F1 having 10MB, F2 having 90MB, F3 having 40MB as it was not use at all, F4 having 5MB, F5 having 115MB and F6 having 10MB.

Using Best-fit

  1. P1 will be allocated to F4. Therefore, F4 will have a remaining space of 5MB from (205 - 200).
  2. P2 will be allocated to F3. Therefore, F3 will have a remaining space of 25MB from (40 - 15).
  3. P3 will be allocated to F6. Therefore, F6 will have no remaining space as it is entirely occupied by P3.
  4. P4 will be allocated to F1. Therefore, F1 will have a remaining space of of 25MB from (100 - 75).
  5. P5 will be allocated to F5. Therefore, F5 will have a remaining space of 125MB from (300 - 175).
  6. P6 will be allocated to the part of the remaining space of F5. Therefore, F5 will have a remaining space of 45MB from (125 - 80).

The remaining free space while using Best-fit include: F1 having 25MB, F2 having 170MB as it was not use at all, F3 having 25MB, F4 having 5MB, F5 having 45MB and F6 having no space remaining.

Using Worst-fit

  1. P1 will be allocated to F5. Therefore, F5 will have a remaining space of 100MB from (300 - 200).
  2. P2 will be allocated to F4. Therefore, F4 will have a remaining space of 190MB from (205 - 15).
  3. P3 will be allocated to part of F4 remaining space. Therefore, F4 will have a remaining space of 5MB from (190 - 185).
  4. P4 will be allocated to F6. Therefore, the remaining space of F6 will be 110MB from (185 - 75).
  5. P5 will not be allocated to any of the available space because none can contain it.
  6. P6 will be allocated to F2. Therefore, F2 will have a remaining space of 90MB from (170 - 80).

The remaining free space while using Worst-fit include: F1 having 100MB, F2 having 90MB, F3 having 40MB, F4 having 5MB, F5 having 100MB and F6 having 110MB.

Explanation:

First-fit allocate process to the very first available memory that can contain the process.

Best-fit allocate process to the memory that exactly contain the process while trying to minimize creation of smaller partition that might lead to wastage.

Worst-fit allocate process to the largest available memory.

From the answer given; best-fit perform well as all process are allocated to memory and it reduces wastage in the form of smaller partition. Worst-fit is indeed the worst as some process could not be assigned to any memory partition.

8 0
3 years ago
the majority of refrigeration systems in residential comfort cooling systems use what type of system?
DIA [1.3K]

Air conditioning, or cooling, is more complicated than heating. Instead of using energy to create heat, air conditioners use energy to take heat away. The most common air conditioning system uses a compressor cycle (similar to the one used by your refrigerator) to transfer heat from your house to the outdoors.

Picture your house as a refrigerator. There is a compressor on the outside filled with a special fluid called a refrigerant. This fluid can change back and forth between liquid and gas. As it changes, it absorbs or releases heat, so it is used to “carry” heat from one place to another, such as from the inside of the refrigerator to the outside. Simple, right?

Well, no. And the process gets quite a bit more complicated with all the controls and valves involved. But its effect is remarkable. An air conditioner takes heat from a cooler place and dumps it in a warmer place, seemingly working against the laws of physics. What drives the process, of course, is electricity — quite a lot of it, in fact. Hope this helps?


7 0
3 years ago
What is your idea for creating a new and fresh Gaming experience around viewing occasions for Mike's?
Whitepunk [10]

My idea on creating a new and fresh Gaming experience around viewing occasions is that one should incorporate emotions into games that people around  around viewing occasions can feel.

<h3>What is a gaming experience?</h3>

Gaming is known to be that experience or one can say the origin of identity and also the community that is made for gamers.

Note that the experience is one that goes far more than the game itself, and as such, My idea on creating a new and fresh Gaming experience around viewing occasions is that one should incorporate emotions into games that people around  around viewing occasions can feel.

Learn more about Gaming experience from

brainly.com/question/27355039

#SPJ1

6 0
2 years ago
Help ne please!! Even if I press 3 times it doenst work.. when I try to turn it off either. Any suggestions? (using ipad)​
arlik [135]

Answer: Have you tried restarting your ipad or Shutting down? Or closing your ipad and waiting for a little bit so It can leave Or you can try Pressing it harder.

Explanation:

Thats all I have to help

8 0
3 years ago
Why are there so many problems with drivers?
podryga [215]

D. hope this helped!!!!!

5 0
3 years ago
Other questions:
  • Why do computers need to periodically check the dns for websites you have already visited? enter your answer here?
    15·1 answer
  • Software engineering design teams use ________, which are grounded in mathematical concepts of sets and relations, for their sof
    13·1 answer
  • Which of the following is true? A)Checks and Debit Cards both withdraw money directly from a bank account. B)Checks are the most
    13·2 answers
  • What is an effective way to display calculations in a Word document
    7·2 answers
  • An athlete runs every day for five days. Write a program that computes the total distance and average distance ran by the athlet
    10·1 answer
  • Name some technologies that engineers create
    13·1 answer
  • Which security control is most helpful in protecting against eavesdropping on wireless LAN (WLAN) data transmissions that would
    6·1 answer
  • Assume that another method has been defined that will compute and return the student's class rank (Freshman, Sophomore, etc). It
    8·1 answer
  • What does the internet engineering task force (IEFT) do?
    5·1 answer
  • What is the best approach to testing a website? visit all pages to verify that they load visit every page and verify all links v
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!