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
The following function open_file() opens a file called 'example.txt' and returns the file pointer. This function is called withi
dsp73

Answer:

Code is given as below:

Explanation:

def open_file():

   fpointer = open('example.txt')

   return fpointer

def main():

   dictlist = []

   dict_of_words = dict()

   fp = open_file()

   # loop to iterate over lines in file

   for line in fp:

       for word in line.split():

           if(not dict_of_words.get(word)):

               dict_of_words[word] = 1

           else:

               dict_of_words[word] += 1

   for key, value in dict_of_words.items():

       temp = (key.lower(), value)

       dictlist.append(temp)

   print(sorted(dictlist))

main()

8 0
3 years ago
Is pseudocode obtained from Algorithm or is Algorithm obtained from pseudocode?
Anuta_ua [19.1K]

Answer:

An algorithm is defined as a well-defined sequence of steps that provides a solution for a given problem, whereas a pseudocode is one of the methods that can be used to represent an algorithm.

hope this gives you at least an idea of the answer:)

8 0
3 years ago
This list represents the horses leading in a race: leadHorses ← ["Justify", "Bravazo", "Good Magic", "Tenfold", "Lone Sailor", "
IrinaVladis [17]

Answer:

leadHorses ← ["Justify", "Bravazo", "Good Magic", "Lone Sailor", "Tenfold",  "Sporting Chance", "Diamond King", "Quip"]

Explanation:

leadHorses ← ["Justify", "Bravazo", "Good Magic", "Tenfold", "Lone Sailor", "Sporting Chance", "Diamond King", "Quip"]

tempHorse ← leadHorses[3]

tempHorse ← Tenfold

leadHorses[3] ← leadHorses[4]

leadHorses[3] ← Lone Sailor

leadHorses[4] ← tempHorse

leadHorses[4] ← Tenfold

leadHorses ← ["Justify", "Bravazo", "Good Magic", "Lone Sailor", "Tenfold",  "Sporting Chance", "Diamond King", "Quip"]

Tenfold and Lone Sailor swap positions.

5 0
3 years ago
While rendering the homepage of a website, it takes a lot of time due to the thread being blocked in processing JS/CSS. What are
jekas [21]

Answer:

a) Pick ONE OR MORE options Using code-splitting for JS files.

b) Compressing the JS files on the server-side

Explanation:

Javascript is a multi-purpose programming language, it is used in web development as a scripting language for programming the interactiveness of the web application.

Loading and running the script from the server can take a lot of time, so, the file is compressed and split for faster loading.

6 0
3 years ago
NEEEEEEEEEEEEEEEEEEEEEEEEEEED HELP PLZ HURRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
AveGali [126]

Answer:

The first step after selecting the File tab is to select <u>New</u>

Explanation:

Invoice templates are used in order to streamline the billing in business.

In order to use such templates by fetching them online such as from Office.com following steps should be followed:

  • Start the Microsoft Word software.
  • Click on File tab.
  • From the drop down memory choose New.
  • In the Search menu type Invoices and it will display all available templates of Invoices.
  • On the homepage, their will be be an option for More Templates below the available ones. Click on it and choose the Category from left and click Invoices.
  • Select the template you want to use.

<h3>I hope it will help you!</h3>
7 0
4 years ago
Other questions:
  • One form of the IF field is called an If…Then…Else: If a condition is true, then perform an action; else perform a different act
    15·2 answers
  • Which is the most common drive letter where Windows stores most data and programs? A. A B. B C. C D. E
    12·2 answers
  • How is a technical certificate like a computer-related associate degree?
    12·2 answers
  • An employee clicks on a link in an email from what looks like a fellow employee and is taken to a fraudulent web site which asks
    6·2 answers
  • Are scripted languages easier or more difficult to port than programming languages? Why?
    6·1 answer
  • Write a method that takes in a String and returns a new
    15·1 answer
  • In many multiprocessor systems __________ is used rather than dedicated processor assignment; in order to evenly distribute work
    14·1 answer
  • Which option is used in Access to locate and retrieve data that may be present in multiple database tables within the database?
    8·1 answer
  • No spamming or links
    15·2 answers
  • Which of the following can be used to enter or display one complete row of information in a range or table without scrolling hor
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!