of words. You [6 marks ] Students are often asked to write papers containing a c
ID: 3712018 • Letter: O
Question
of words. You [6 marks ] Students are often asked to write papers containing a certain number are asked to write a method that accepts a Scanner (that has been initialized to an input file containing a draft of a paper), counts the number of words in the file. Assume that consecutive words are separated either by spaces or end-of-line characters. A sample input file and the method header are provided below J'ai choisi la question: "Quand la neige est comprimée, est-ce que la température change?". J'ai décidé de faire ce projet, car j'adore skier et tout ce qui concerne la neige. Pour l'expérience, j'ai utilisé un contenant avec son couvercle transforme en piston. J'ai mis un thermomètre avec une sonde en bas et j'ai mesuré la température avant et après la compression. J'ai fait de mon mieux pour maintenir les variables constants d'un test à l'autre. Par exemple, je me suis assurée que le contenant soit de la même température que la neige et j'ai essayé de mettre la même quantité de neige dans le contenant chaque fois. J'ai découvert que la neige se réchauffe, car en la comprimant, la pression augmente. C'était un projet super amusant! Sample input file: /wod cout, codt bons inofle /Lwput a Scanner to au inpit file Return the kumbe r of words 'in -the public static int wordCount (Scanner inFile)Explanation / Answer
public static int wordCount(Scanner inFile)
{
int count = 0;
while(inFile.hasNext())
{
inFile.next();
count++;
}
inFile.close();
return count;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.