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
Named constants should be used when they serve to improve readability and understanding. T or F
prisoha [69]
The answer is true.

Let's say we are calculating the volume of a grain silo where the the width is a constant, but the height can be changed.

In our code we would calculate the volume using something like:

PI * (WIDTH / 2)^2 * height

The variables in all caps would be named constants. Using them makes the code more readable to other people than if we were to just use their values like:

3.14 * (145.75 / 2)^2 * height




8 0
3 years ago
Read 2 more answers
Please select all examples of systems using guided media. Group of answer choices ADSL 802.11 Wifi Home Networks Global Position
dusya [7]

Answer:

- ADSL.

- Ethernet Home Networks.

- Fiber Optics.

- Cable Television.

Explanation:

In Computer, Guided media also known as bounded media involves the use of cable such as fibre-optic cables, coaxial cable to transmit data signals from one system device to another.

Examples of systems using guided media are;

- ADSL.

- Ethernet Home Networks.

- Fiber Optics.

- Cable Television.

7 0
3 years ago
Most network cards contain a port that accepts a(n) ____, which looks similar to a telephone connector but is larger.
Vadim26 [7]
YOUR ANSWER IS -------- It accepts a RJ-45 connector
hope i helped you :).
take care
8 0
3 years ago
Which of the following is not a type of bank? A.Credit Union B.Online Bank C.Payday Lender D.Retail Bank
Damm [24]
C. a payday lender is a type of loan
7 0
3 years ago
The ____ command sends a small tcp/ip packet to another ip address and awaits a response.
Anuta_ua [19.1K]
In *nix, the ping command keeps on sending ICMP packets unless the "-c" (count) argument is passed. In Windows, ping defaults to 4 ICMP packets.
7 0
3 years ago
Other questions:
  • Codio Challenge Activity PythonWe are passing in a list of numbers. You need to create 2 new lists in your chart, then put all o
    13·1 answer
  • It is always better to run over and give more information when you are giving a presentation versus quitting on time. true false
    15·2 answers
  • How does a hard drive work
    15·1 answer
  • 18) choose which article title would most likely be described by the database subject headings victims of famine, ireland, histo
    14·1 answer
  • Can a spreadsheet be filtered only by one column at a time?
    11·1 answer
  • Is it possible for the front and rear references in a circular array implementation to be equal?
    8·1 answer
  • What is an effective way to record change management? (5 points)
    9·1 answer
  • A ______________ is a way of taking a screenshot or a picture of your computer screen. ​
    14·1 answer
  • MmfbfMMMMMMMMMMMMMMMMMmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
    14·1 answer
  • What number will this code return?<br> Math.max(7, 5, 9);
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!