Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i am doing a program where I am reading from an attached file ......hello.txt an

ID: 3529728 • Letter: I

Question

i am doing a program where I am reading from an attached file ......hello.txt and that file contains "The sodas are in the fridge". I have to replace all the vowels by "$" and count the words that start with "th" such that my output would look like this..... Th$ s$d$s $r$ $n th# fr$dg$ and there are 2 words that starts with "th"....... This is what I have so far............. public class Hello { public static void main(String [] args) throws IOException { File inputFile = new File( "hello.txt"); Scanner scan = new Scanner ( inputFile ); String word = scan.nextLine(); int count = 0; String VALID_SENTENCE_PATTERN = "[a-zA-Z]{ }[a-zA-Z]{ }[a-zA-Z]{ }[a-zA-Z]"; String sentence2 = SENTENCE.replaceALL("[aeiou]","$"); while (scan.hasNext()) { if (word.equalsIgnoreCase("th")) count ++; word = scan.nextLine(); System.out.println(word); } System.out.println(sentence2 + " and there are " + word + " words that start with th "); } } it is not compiling.......I need help on this whole program

Explanation / Answer

This is the exact working code.and i have checked it in eclipse.


You have to change the location of file only.

Please rate.

----------------------------------------------------------------------

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class Hello {

public static void main(String[] args)throws IOException
{

File inputFile = new File("C:/AmitKumar/Eclipse_Workspace/Demo/src/hello.txt");
Scanner scan = new Scanner ( inputFile );
String input=scan.nextLine();
String[] words = input.split("\s+");
int count=0;

input=input.replace('a','$');
input=input.replace('e','$');
input=input.replace('i','$');
input=input.replace('o','$');
input=input.replace('u','$');
System.out.println( input );

for(int i=0;i<words.length;i++)
{
String temp=words[i].toLowerCase();
if(temp.charAt(0)=='t'&& temp.charAt(1)=='h')
{
count++;
}
}
System.out.println("Number of word start with th is : "+count);
}
}

----------------------------------

output

--------------------------

Th$ s$d$s $r$ $n th$ fr$dg$
Number of word start with th is : 2