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]
2 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]2 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
Wite 3 names of computers used in 1st generation of computers?
enyata [817]
Here are some of the computers used in the first generation of computers:
ENIAC
EDVAC
UNIVAC
IBM-701
IBM-650
These are some of the first computers ever that led to today's computers.
5 0
2 years ago
History of computer from difference engine <br>​
harkovskaia [24]

Answer:

Charles Babbage (1791-1871), computer pioneer, designed two classes of engine, Difference Engines, and Analytical Engines. Difference engines are so called because of the mathematical principle on which they are based, namely, the method of finite differences.

Explanation:

4 0
2 years ago
Read 2 more answers
"when a dynamic web page is requested, the web server passes the request to"
nalin [4]
System operations of the website u are  asking to access
7 0
3 years ago
Many financial experts advise that property owners should insure their homes or buildings for at least 80 percent of the amount
serious [3.7K]
All I will say is good luck. because it can be very difficult to find someone that is willing to do this.
5 0
3 years ago
Given a variable s that is associated with the empty string, write some statements that use a while loop to associate s with a s
ArbitrLikvidat [17]

Answer:

Following are the program in the Python Programming Language.

#declare empty string variable

s=""

#declare variable that store "*" as string

x= "*"

#set the while loop

while(len(s) < 777):

   #initialize the value of 'x' in 's'

   s= x

   x += "*"

Explanation:

<u>Following are the description of the program</u>.

  • Set an empty variable to store the string type values.
  • Again, set a variable 'x' and initialize asterisks in it as a string.
  • Set the while loop that iterate, when the length of the variable 's' is less than 777, then initialize the value of the variable 'x' in the variable 's' and concatenate asterisks with the variable 's'.
8 0
3 years ago
Other questions:
  • How many megabytes of data can a factory made audio cd hold?
    13·1 answer
  • Which statement best describes multimedia
    14·1 answer
  • Consider the following code segment: ArrayList bulbs = new ArrayList(); bulbs.add(new Light()); bulbs.remove(0); bulbs.add(new L
    15·2 answers
  • Students who respond promptly to e-mails are following which netiquette rule?
    13·2 answers
  • Suppose users share a 1-Gbps link. Also, suppose each user requires 200 Mbps when transmitting, but each user only transmits 30
    5·1 answer
  • How do you resolve conflicts in your life??
    11·1 answer
  • Is it better to try to prevent damage from natural disasters or to deal with disasters after they occur?
    10·2 answers
  • What is this error SyntaxError: Unexpected token '??='
    12·1 answer
  • You have just received a generic-looking email that is addressed as coming from the administrator of your company. The email say
    8·1 answer
  • Typically, hybrid drives use SSD to store the operating system and applications and hard disks to store videos, music, and docum
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!