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
mamaluj [8]
3 years ago
15

Write a program which takes a string and a word from the userand search that word in the string and count how many timesthat wor

d comes in the string.
Computers and Technology
1 answer:
GuDViN [60]3 years ago
7 0

Answer:

Following is the Java Code:-

import java.io.*; // package of java input output

import java.util.*; // package for using scanner class  

class Main{  

static int count(String str, String word) // create as function

{  

String a1[] = str.split(" "); // splitting the string by space

int c = 0; // initialization of count variable

for (int k = 0; k< a1.length; k++)  

{  

if (word.equals(a1[k])) // match the string to word if condition is matched

c++; // increment of count

}  

return c++;  

}  

public static void main(String args[]) // main method

{  

Scanner ob1 = new Scanner(System.in); // Creating a Scanner object

System.out.println("Enter the string:");

String str1,word1;  

str1= ob1.nextLine();

System.out.println("Enter word you want to search without spaces:");

word1 = ob1.nextLine();

System.out.println(count(str1, word1)); // calling and printing ther word

}  

}

Output:-

Enter the string:

deep das dev das

Enter the word you want to search without spaces :

das

2

Explanation:

I have taken an array of strings to store the words in the string entered and checking the word entered is equal to any word in the string if it is then updating the count.After that returning the count .

You might be interested in
What is the function below Missing?
Nat2105 [25]

Answer:

I think a closing bracket.. sorry if its wrong.

Explanation:

3 0
3 years ago
Read 2 more answers
Assume a program requires the execution of 50 x 106 FP instructions, 110 x 106 INT instructions, 80 x 106 L/S instructions, and
Molodets [167]

Explanation:

FP - 50 \times 10^6

CPI - 1

INT -110 \times 10^6,

CPI - 1

I/S - 80 \times 10^6 ,

CPI - 4

Branch - 16 \times 10^6

CPI - 2

Clock Speed - 2 \times 10^9

Time(old) =\frac{50 x 10^6 + 110 x 10^6 + 4 x ( 80 x 10^6) + 2 x (16 x 10^ 6)}{2 x 10^9}

Time(old) = 256 \times 10^ {-3}

Time(new) =  \frac{256 \times 10^{-3}}{2}

                = 128 \times 10^{-3}

                =\frac{CPI(new) x [50 x 10^6 + 110 x 10^6 + 4 x ( 80 x 10^6) + 2 x (16 x 10^ 6)]}{2 x 10^9}

                =  128 \times 10^{-3}

CPI(new) = \frac{-206}{50}

               = -4.12

3 0
3 years ago
Which mobile game do play most pubg or call of duty mobile ​
Katena32 [7]

Answer:

Neither game, does anyone remember Angry Birds Epic though

Explanation:

That game brings me nostalgia

6 0
3 years ago
Read 2 more answers
Does a computer have a primary and secondary memory?????? Please help me.
deff fn [24]
It probably has back ups
8 0
4 years ago
Read 2 more answers
How operands are fetched from or stored into memory using different ways?
Mila [183]
<span>The operand is part of the instruction and is fetched from code memory following the instruction opcode.
</span><span>The value is stored in memory, and the specific address is held in a register</span>
6 0
4 years ago
Other questions:
  • Answer: x = 3<br>#1 -2x + 5 = -31​
    10·1 answer
  • When you close a file, what happens to the undo history list for that file?
    5·1 answer
  • Which are valid double statements for java? double a = 0; double b = -1.0; double c = -425; double d = 6340; double e = -1.0; do
    12·2 answers
  • What special skill does a developer need to thelp produce timely solutions for users
    7·1 answer
  • The class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not c
    6·2 answers
  • If there is only a stop sign posted at a railroad
    9·1 answer
  • Lesson 12: while loops with the farmer. Number 9.
    10·2 answers
  • What is the most important job of a web server?
    11·2 answers
  • What is an example of new technology having a negative impact on sustainability?.
    7·1 answer
  • PLEASE HELP!
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!