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
chubhunter [2.5K]
2 years ago
9

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. The output should include the input character and use the plural form, n’s, if the number of times the character appears is not eactly 1.
Ex if the input is: n Monday
the output is: 1 n
Ex: if the input is: z Today is Monday
The output is 0 z’s
Ex: if the input is: n It’s a Sunday day
the output is: 2 n’s
case matters
Ex: if the input is: n Nobody
the output is: 0 n’s
N is different than N.


I need help putting it in Java

Computers and Technology
1 answer:
Eva8 [605]2 years ago
6 0

Answer:

class Main {

 public static void analyzeString(char c, String s) {

   int count = 0;

   for(int i=0; i<s.length(); i++) {

     if (s.charAt(i) == c) {

       count++;

     }

   }

   

   System.out.printf("%c %s\n", c, s);

   System.out.printf("%d %c%s\n\n",count, c, count==1 ? "":"'s");

 }

 

 public static void main(String[] args) {

   analyzeString('n', "Monday");

   analyzeString('z', "Today is Monday");

   analyzeString('n', "It’s a Sunday day");

   analyzeString('n', "Nobody");

 }

}

Explanation:

I did not add code to prompt the user for input, but rather added the test cases as you provided.

By the way, there is only one 'n' in 'It's a Sunday day'. So the example is wrong there.

You might be interested in
100 POINTS NEED THIS BEFORE 11:59 TODAY!!!!!!!!!!!!!!!
AVprozaik [17]

Answer:ok be how hobrhkihfehgdhdj fuiufiisefif jfkijfjfhhfhfhfhf

Explanation:

5 0
3 years ago
What is often called a platform, a collection of computer programs that work together to manage hardware and software to ensure
Nady [450]

Answer:

The correct answer to the following question will be "Operating system".

Explanation:

  • An operating system is a machine software that handles hardware of a computer, computing assets and delivers basic services to software programs.
  • It is an intermediary between such users and computer hardware.
  • It also helps you to interact with your machine without learning how to use your language of the computer.

Therefore, it will be the right answer.

7 0
3 years ago
Is jesus dead or alive
Morgarella [4.7K]

Answer:

Explanation:

i think he alive but in heaven i dunno

8 0
3 years ago
You create a storyboard at the _____ stage of web development
ddd [48]

Answer:

initial stage of web development.

4 0
4 years ago
Read 2 more answers
HEEEEELPPP!!!BRAINLIEST!!! THIS IS URGENT!!!
Fittoniya [83]

Answer:

Begin the statement with the proper keyword to start the loop

Explanation:

Given

The code segment

Required

Fix the code

The first line of the code segment is meant to be a for loop, but it does follow the right syntax.

This is so because the for keyword is missing.

The first line should be corrected and replaced with:

for count in range(80):

Hence, option (b) is correct

4 0
3 years ago
Other questions:
  • A publisher has a text-only leader board on top of a page, and a text-only small square ad slot within the content of that page.
    7·1 answer
  • Which of the following correctly describes the reason for quality customer service?
    15·2 answers
  • What kind of printer is used with multipart forms such as those with point of sale machines?A) dot-matrixB) daisy-wheelC) inkjet
    5·1 answer
  • PrimeFactorization.java: Write a program that begins by reading in a series of positive integers on a single line of input and t
    12·1 answer
  • What is the BCC feature used for?
    12·2 answers
  • 1. Which sentence best expresses the main idea
    12·1 answer
  • Compare and contrats the vain digestive system from the human digestive system.​
    10·1 answer
  • 30 Points!!
    13·2 answers
  • Your friend says, “I can’t ever watch a streaming movie without it pausing for long moments. It makes me crazy!” What might you
    11·1 answer
  • what extension of nat allows several hundred workstations to access the internet with a single public internet address
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!