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
bagirrra123 [75]
3 years ago
11

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. You may assume that the string does not contain spaces and will always contain less than 50 characters. Ex: If the input is: n Monday the output is: 1 Ex: If the input is: z TodayisMonday the output is: 0 Ex: If the input is: n It'ssunnytoday the output is: 2 Case matters. Ex: If the input is: n Nobody the output is: 0 n is different than N.
Computers and Technology
1 answer:
Delvig [45]3 years ago
5 0

Answer:

// program in java.

import java.util.*;

// class definition

class Main

{

   // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

   try{

    // object to read input  

Scanner scr=new Scanner(System.in);

 System.out.print("Enter the String:");

  // read string from user

   String str=scr.nextLine();

System.out.print("Enter the character:");

 // read character

char ch=scr.next().charAt(0);

  // variable to count the occurrence of character  

   int char_count=0;

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

   {

   // find the character i string

       if(ch==str.charAt(i))

       // increase the count

       char_count++;

   }

   // print the count

   System.out.println("count of "+ch+" in the String is:"+char_count);

   }catch(Exception ex){

       return;}

}

}

Explanation:

Read a string from user and assign it to variable "str".Then read a character to  and assign it to variable "ch".Then Declare a variable "char_count" to count the  occurrence of character in the string.Find the count of character in the string. Here upper case character is different than lower case.  

Output:

Enter the String:Monday                                                                                                    

Enter the character:n                                                                                                      

count of n in the String is:1

Enter the String:Nobody                                                                                                    

Enter the character:n                                                                                                      

count of n in the String is:0                                                                                              

                             

You might be interested in
In the range C15:G15, insert a function to calculate the total daily revenue. In the range H11:H15, insert a function to calcula
lina2011 [118]

Answer:

1. =SUM(C15: G15) 2. The first part of second part is =SUM(C11:G11), =SUM(C12:G12), =SUM(C13:G13), =SUM(C14:G14), =SUM(C15:G15).  Last is total revenue and the first four are seating for various classes and the second part of the second question is =SUM(H11: H14)  which is the grand total of seats.

Explanation:

Suppose from C15 to G15, we have five columns and hence five days. So we can have one column for one day, and add there, number of seats. C15: G15 is daily revenue, and C11: G11 ...... C14: G14 is the number of seats each day, and in each class, and thus the above answer. We can have different assumptions, and formula will change according to assumptions. You can use HLOOKUP as well if you want.

3 0
3 years ago
Each peripheral device has its own software, called a(n) ____, which contains the detailed instructions required to start that d
olga nikolaevna [1]
OS or operating system
4 0
3 years ago
Phil wants to make a dark themed superhero movie. What could be his target demographic
maria [59]

Answer:

d

Explanation:

i think, because it makes the most sense to me.

5 0
3 years ago
Read 2 more answers
The encapsulation unit on the presentation layer of the osi model is
Zielflug [23.3K]
<span>The encapsulation unit on the presentation layer of the OSI model is the Data link layer (2).</span>
7 0
3 years ago
Initialize the tuple team_names with the strings 'Rockets', 'Raptors', 'Warriors', and 'Celtics' (The top-4 2018 NBA teams at th
dexar [7]

Answer:

Following is the code in python language

team_names = ('Rockets','Raptors','Warriors','Celtics')#holding the string value

print(team_names[0],team_names[1],team_names[2],team_names[3])#display

Output:

Rockets Raptors Warriors Celtics

Explanation:

Following is the description of above statement .

  • Create a dictionary "team_names" that is holding the string value Rockets Raptors Warriors and Celtics.
  • Finally we used the print function in that function we pass the index of corresponding dictionary i.e team_names[0] . it will display the first index value  similarly we pass  team_names[1], team_names[2]  team_names[3].
8 0
3 years ago
Other questions:
  • Elvis has asked Bonnie out on a date to a baseball game. Elvis is a friend of Bonnie's classmate Ginger and she has met him a fe
    5·2 answers
  • Help what is a computer made from (computer class question)!!
    9·1 answer
  • Ashley works for a movie theater. The theater has decided to host some special events over the summer. She needs to communicate
    8·2 answers
  • Which type of graph or chart measures
    15·2 answers
  • In "When Is a Planet Not a Planet?" why does the author say that the outer planets are made of gas when the inner planets are ma
    5·1 answer
  • How do you copy and paste plz let me know
    14·2 answers
  • Given two int variables , firstplacewinner and secondplacewinner, write some code that swaps their values . declare any addition
    11·1 answer
  • Phishing (pronounced fishing) is malware sent through e-mail that looks like a legitimate message from a trusted sender. The goa
    10·2 answers
  • How many atoms of oxygen in 4 molecules of HN03​
    12·1 answer
  • How can you create a messages to look like an IMessage?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!