Question

Please Solve the Question by Using Java Programming and do exactly as per the question asked......

Please Solve the Question by Using Java Programming and do exactly as per the question asked......

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code is

public class Test

{

public static int WordCount(String s)

{

if(s.equals(""))return 0;

int count=1;

int index=s.indexOf(' ');

while(index!=-1)

{

count++;

index=s.indexOf(' ',index+1);

}

return count;

}

public static String arrayToString(char[] arr)

{

String s="";

for(char c:arr)

s+=c;

return s;

}

public static char mostFrequent(String s)

{

int count[] =new int[26];

for(int i=0;i<26;i++)count[i]=0;

char[] arr=s.toCharArray();

for(char c: arr)

{

if(c!=' ')

count[c-'a']++;

}

int m=0;

int c1=0;

for(int i=0;i<26;i++)

{

if(count[i]>c1)

{

c1=count[i];

m=i;

}

}

return (char)(m+'a');

}

public static String replaceSubstring(String s,String a,String b)

{

return s.replaceAll(a,b);

}

public static void main(String[] args)

{

String string1="the dog jumped over the fence";

String string2="the";

String string3="that";

System.out.println("Number of words in \""+string1+"\" is "+WordCount(string1));

System.out.println("Most frequently occuring character: "+mostFrequent(string1));

System.out.println(replaceSubstring(string1,string2,string3));

System.out.println("How now brown cow");

}

}

Do give a thumbs up

Add a comment
Know the answer?
Add Answer to:
Please Solve the Question by Using Java Programming and do exactly as per the question asked......
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • SOLVE THE PSEUDOCODE ONLY. PLEASE DO NOT CODE IT. PROGRAMMING LOGIC AND DESIGN. JAVA. Q.6.2 Using...

    SOLVE THE PSEUDOCODE ONLY. PLEASE DO NOT CODE IT. PROGRAMMING LOGIC AND DESIGN. JAVA. Q.6.2 Using pseudocode, write the code that will perform the necessary file operations as described in the short scenario below: "During registration at a college, student's details will be captured by a staff member and written to a file called "student Details.dat". The following student details will be captured: name, surname, student Number, registered Course. The staff member will be prompted for the student details. After...

  • run III please write the codes and do exactly what they asked runIV plot by HAND...

    run III please write the codes and do exactly what they asked runIV plot by HAND and use MATLAB also -will get tumbs up RUNWIN Use Matlab to solve the following non-linear equation: sin(w. ) - cos (w. ), for tan(w. ) sin(w. ) +12 for /2 RUNWIV I + + 2 Obtain plots by hand and by using Matlab of the following equation: (D) sin( +90°) vs. radians, degrees and time

  • java programming!!! Write the code fragment that will do the following: • Ask the user how...

    java programming!!! Write the code fragment that will do the following: • Ask the user how many numbers they want to enter • Declare and instantiate an array of doubles with as many elements as the number entered by the user • Write one 'for' loop to fill the array with data from the user • Write a second 'for' loop to calculate the sum of all of the numbers in the array • Print the calculated sum Note: Write...

  • Solve this: Using this method exactly but with the differences asked. Program: Read the Inputs and...

    Solve this: Using this method exactly but with the differences asked. Program: Read the Inputs and Turn them into Outputs, Toggle PORTC bit o. Write an assembly language program for the PIC18F4520 to read 4 most significant bits switch input on bits 7-4). For each switch that is in the "ON" or high position, compliment the inputs and output the bits to PORTB, least significant bits (PORTB bits 3-0) as outputs. Repeat the procedure every 500 msec. Simultaneously Togale bit...

  • Java programming: The following java code is supposed to solve a linear equation of the form...

    Java programming: The following java code is supposed to solve a linear equation of the form aX+b = 0 where a and b are real numbers. However, there are some errors, nd and x them using a combination of exceptions and control statements. Hint. What could go wrong in the execution of this program? /*********************************************/ // here is the code I have: import java.util.*; public class Solver{ public static void main(String[] args){ System.out.println("Let us solve an equation of the form...

  • Hi, I have Java programming problem: Please solve using Java. Thanks. Best Regards. In the army,...

    Hi, I have Java programming problem: Please solve using Java. Thanks. Best Regards. In the army, each soldier has an assigned rank. A soldier of rank X has to report to (any) soldier of rank X + 1. Many soldiers can report to the same superior. Write a function: class Solution { public int solution(int[] ranks); } that, given an array ranks consisting of soldiers' ranks, returns the number of soldiers who can report to some superior. Examples: 1. Given...

  • Programming in Java. Please attached the screenshot of source code and the output Thanks. Java Programming:...

    Programming in Java. Please attached the screenshot of source code and the output Thanks. Java Programming: A Comprehensive Introductia See this solution in the app :3 Chapter 3, Problem 17E Bookmark Show all steps: 0 ON Problem Write a program that uses a loop to print a list of 100 numbers consisting of alternating 1's and -1's, starting with 1.

  • java programming Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for...

    java programming Problem 2) Convert Kilometers to Miles Write a JavaFX program using JavaFX Menu for to solve the following problem about converting between Kilometers to Miles. Sample Run is shown below You are asked to implement only the menu item under Formulas which reads as"KM to Mile". Choosing this menu item will display the following input box: Input Enter Kilometers Value OK Cancel The result will be displayed in a TextArea as shown below: JavaF× Menu Example " File...

  • please use c++ to solve question The best way to learn programming is practice by solving...

    please use c++ to solve question The best way to learn programming is practice by solving problems. Find a small but interesting project for yourself to work on the rest of the days of this summer. Do some research online about what you want to do. Then write a title for it and a few lines describing it.

  • Please Solve in C programming. Please Use “ f(x) = e^(-x^2) “ for thus question. Thank You

    Please Solve in C programming. Please Use “ f(x) = e^(-x^2) “ for thus question. Thank You rite computer code in any programming language or mathematical software to estimate he following derivatives. Then calculate the absolute and relative errors for each: I, f"(1.5) for f(z) in Question 3 above using the three-point formula. Use h 0.5 rite computer code in any programming language or mathematical software to estimate he following derivatives. Then calculate the absolute and relative errors for each:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT