18) Write a complete Java program using the StringTokenizer class that computes and displays the average of a list of grades read from the command line. Each grade should be entered on the same line separated by commas. Enter signifies the end of the input.
What will be an ideal response?
```
import java.util.Scanner;
import java.util.StringTokenizer;
public class tokenAverager
{
public static void main(String[] args)
{
//Local variables
Scanner keyboard = new Scanner(System.in);
int sum = 0;
int count = 0;
double average = 0;
System.out.println("Enter your grades, placing a space between each grade.");
System.out.println("Press enter when you are finished.");
String grades = keyboard.nextLine();
StringTokenizer tk = new StringTokenizer(grades, " ");
while(tk.hasMoreTokens())
{
sum += Integer.parseInt(tk.nextToken());
count++;
}
average = sum/count;
System.out.println("The class average is " + average);
}
}
```
You might also like to view...
The endnotes line can be removed from a document
Indicate whether the statement is true or false
The and are special XHTML elements in that they can both act as inline and block-level elements.
Answer the following statement true (T) or false (F)
Which of the following consists of one or more chips on the motherboard that hold items such as data and instructions while the processor interprets and executes them?
A. ROM B. RAM C. BIOS D. POST
ROM refers to a faster type of RAM that is installed only on high-end systems or network servers.
Answer the following statement true (T) or false (F)