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
vova2212 [387]
3 years ago
13

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. Ex: If the input is: n Monday, the output is:
Computers and Technology
1 answer:
riadik2000 [5.3K]3 years ago
3 0

Answer:

import java.util.Scanner;

public class ANot {

   public static void main(String[] args) {

       System.out.println("Enter a character");

       Scanner in = new Scanner(System.in);

       char character = in.next().charAt(0);

       System.out.println("Enter a string");

       String string = in.next();

//Calling the method        

System.out.println(countChar(character,string));

   }

   public static int countChar(char a, String in){

       int counter =0; // initialize counter

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

           if(a == in.charAt(i))

               counter++;

       }

       return counter;

   }

}

Explanation:

This program is written in Java Programming language.

We created a method countChar that returns a integer called counter

Using a for loop in the method we iterate through the string object and check (a == in.charAt(i)) so as to increase counter when ever there is a match.

In the main method a Scanner Class is used to request user to input a character and a string which is passed to countChar when called.

NOTE that this program has considered lower case letters to be different from upper cases as such a is not equal to A

You might be interested in
Suppose that, when you arrive at the sale site for $50 Apple laptops (described in the text) at 1:45 A.M., you find more than 2,
const2013 [10]

Full question:

Suppose that, when you arrive at the sale site for $50 Apple laptops (described in the text) at 1:45 A.M., you find more than 2,000 people already waiting for the site to open. You turn around and go home to get some sleep. Later you buy an Apple laptop, the same model as the $50 one, for $1,070. This indicates that ________.

Answer:

your opportunity cost of waiting at the site (and pushing and shoving) is at least $1,020

Explanation:

If you had decided to stay and wait and go through the hassle of pushing and grabbing in the queue to get a laptop of $50, you would have saved $1020. This is an opportunity that you have not(forgone) used and so you pay for it in the form of increased price of the apple laptop at $1070.

6 0
3 years ago
Which application requires knowlodge of html or javascript to produce a website
REY [17]

Answer:

Wordpress

Explanation:

WordPress (WP, WordPress.org) is a free and open-source content management system (CMS) written in PHP [source: Wikipedia].

Wordpress can be used to create websites, blogs, ecommerce sites.

HTML provides the basic structure of websites. It is enhanced and modified by other programs such as CSS and JavaScript. CSS is used to control presentation, formatting, and layout. JavaScript is used to control the behavior of different elements.

4 0
4 years ago
Rafi is developing an application to send urgent information about global health crises over the Internet to hospitals. He is wo
Liono4ka [1.6K]
Have the packets virtual
6 0
3 years ago
What are the two types of disks that make up tiered storage?
Andrej [43]
Tiered storage is an underlying principle of ILM (<span>information lifecycle management</span>). It is a storage networking method where data is stored on various types of media based on performance, availability and recovery requirements. For example, data intended for restoration in the event of data loss or corruption could be stored locally -- for fast recovery -- while data for regulatory purposes could be archived to lower cost disks.
6 0
3 years ago
Why will my note 5 not download videos from the web?
meriva
Try downloading an app if the phone is not doing it.
7 0
3 years ago
Other questions:
  • After which problem-solving stage should you take action?
    12·1 answer
  • A _____ attack keeps the target so busy responding to a stream of automated requests that legitimate users cannot get in
    9·1 answer
  • Programming assignment (100 pts): In the C++ programming language write a program capable of playing Tic-Tac-Toe against the use
    14·1 answer
  • To easily add an organizational chart to a document, users should select .
    9·1 answer
  • Implement the above in c++, you will write a test program named create_and_test_hash.cc . Your programs should run from the term
    9·1 answer
  • In what tab can a user find the workspace option?
    8·1 answer
  • When your grounded and the only thing you can get on is a computer........................oh welllllllllllllllllllllllllllllllll
    7·1 answer
  • Convert one billion byte into one storage unit​
    6·1 answer
  • Which of the following is a set of security controls designed to protect payment account security such as a credit card transact
    13·2 answers
  • Ali has created a small program in Python, but he wants to store his data in a multi-dimensional array. He would like to use adv
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!