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
Which file format would be appropriate for web graphics​
Eddi Din [679]

Answer:

PNG

Explanation:

PNG files can shrink to incredibly small sizes - especially images that are simple colours, shapes, or text. This makes it the ideal image file type for Web graphics.

4 0
2 years ago
A ___________ organizes related commands together, under a tab.
notsponge [240]
A menu bar organizes related commands together, under a tab.
So the answer is <span>b. menu bar</span>
8 0
3 years ago
You are troubleshooting a mobile device that will not pair with a Bluetooth headset. The device was functioning properly with th
bulgar [2K]

Answer:

B. Replace the Bluetooth headset with a new pair.

Explanation:

Since all other mobile devices, after receiving the "corporate-wide" OS update, aren't having issues with pairing with Bluetooth headsets, we can safely conclude that the OS update isn't the issue.

To find out if the Bluetooth headset is not the culprit, we can try to pair the mobile device with a different headset. If it pairs correctly, then we can conclude that the old Bluetooth headset might have a fault, or it might need to be disconnected/forget from the device and paired gain.

7 0
2 years ago
Dates of birth were entered into a computer program . The data was stored in the format DAY/MONTH/YEAR.The program rejected this
Marina CMI [18]

Answer:

i. This value was not accepted because we have 12 months and not 13.

ii. This is because the user entered the value for the day as value for the month.

Explanation:

i. Why was this not accepted?

This value was not accepted because we have 12 months and not 13. The user entered a value that was above the maximum value registered for the number of months in a year- which is 12.

ii. Why do you think this error occurred

This is because the user entered the value for the day as value for the month.

This could be because the user uses a date system different from that of the program.

3 0
2 years ago
Cloud computing will offer applications that are _______.
Komok [63]
B. only accesible over the internet
8 0
3 years ago
Read 2 more answers
Other questions:
  • What is the meaning for science?
    14·1 answer
  • Which of the following are incorrect safety precautions for equipment operators? A. Drive equipment or vehicles on grades or roa
    7·2 answers
  • Como hacer una pagina web
    15·1 answer
  • According to Holpp and Kelly's approaches to developing vision, the benchmarking approach is more internally focused, whereas th
    6·1 answer
  • Lydia noticed that she feels tired and out of breath after walking her dog up a hill in the park. Which area of fitness does she
    8·1 answer
  • Two-dimensional random walk (20 points). A two-dimensional random walk simulates the behavior of a particle moving in a grid of
    14·1 answer
  • One condition for deadlocks is the circular-wait condition. One way to ensure that this condition never holds is to impose a tot
    12·2 answers
  • Really helpful, I want to get together tomorrow ,Later I will follow and make it the best answer
    7·1 answer
  • 1: define about information system in computer?
    10·1 answer
  • How do you delete questions you asked?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!