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
[True/False] Mainframes, unlike microcomputers, allow users unlimited and flexible access to computing power.
Lemur [1.5K]

Answer:

The given statement is "False".

Explanation:

Mainframes computer are also known big iron computer basically Mainframe computer is used by the big organization when the organization needs to work in the high-level project. The mainframe has big data processing. It is highly used in critical applications such as ERP(Enterprise resource planning).

A mainframe computer is not a flexible computer also they are not potable .microcomputers, are more flexible computers we can easily work on the microcomputers.

So the given statement is False.

8 0
3 years ago
"So far this month you have achieved $100.00 in sales, which is 50% of your total monthly goal. With only 5 more workdays this m
Rus_ich [418]

Answer:

$20 per day for next 5 working days.

Explanation:

if 50% is $100.00 another $100 need to achieve in 5 days.

100/5=20

3 0
3 years ago
Read 2 more answers
The ASE certification system uses _______ testing and an evaluation of on-the-job experience to confirm that a technician meets
erma4kov [3.2K]
 MY answer would be A or C .Hope this helped
7 0
3 years ago
Read 2 more answers
What is what is a network that is easy to maintain and cheap ​
kifflom [539]

Answer:

Click at the pic above and the ans will appear.

Hope it helps :)

4 0
3 years ago
Can you guys report my last question trying not to get caught for cheating all questions please
AfilCa [17]

Answer:

Yes

Explanation:

mark as best answer please

7 0
3 years ago
Other questions:
  • Although highly accurate navigational information from the GPS constellation is exploitable by adversary forces, it is unlikely
    5·1 answer
  • Write a Python program to do the following:
    12·1 answer
  • Instagram
    9·1 answer
  • THIS IS PYTHON QUESTION
    11·1 answer
  • Identify traits of entrepreneurs. Check all of the boxes that apply.
    11·1 answer
  • In this exercise, you are asking the user to set a alpha numeric password for any website. Put some conditions.
    8·1 answer
  • Debugging 2.17.3: Debug: The Two Towers Code Hs
    15·1 answer
  • Diane, a developer, needs to program a logic component that will allow the user to enter a series of values
    10·1 answer
  • Different Betweens ServerPc And Desktop Pc ~
    15·1 answer
  • It is possible to create a share that is invisible to users browsing the network simply by appending what character to the end o
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!