The purpose of my program is to accept ints, doubles, and strings from the user and when the program is terminated by inputing the word "quit", the program averages the ints and doubles, and outputs the submitted strings. Here is what i have so far:
import java.util.*;
public class Lab09 {
public static void main(String [] args) {
Scanner console = new Scanner(System.in);
double sumI = 0;
double sumD = 0;
String words = "";
int numInputInt = 0;
int numInputDoub = 0;
do {
System.out.print("Enter something: ");
if (console.hasNextInt()) {
int numI = console.nextInt();
if (numI >= -100 && numI <= 100) {
sumI += numI;
numInputInt++;
}
else {
System.out.println("Integer out of range!(-100 .. 100)");
}
}
else if (console.hasNextDouble()) {
double numD = console.nextDouble();
if (numD >= -10.0 && numD <= 10.0) {
sumD += numD;
numInputDoub++;
}
else {
System.out.println("Double out of range!(-10.0 .. 10.0)");
}
}
else {
words = console.next();
}
} while (!words.equalsIgnoreCase("quit"));
System.out.println("Program terminated...");
double avgInt = sumI / numInputInt;
double avgDoub = sumD / numInputDoub;
if (numInputInt > 0) {
System.out.println("\tAveragae of Integers: " + avgInt);
}
else {
System.out.println("\tNo intergers submitted");
}
if (numInputDoub > 0) {
System.out.println("\tAverage of Doubles: " + avgDoub);
}
else {
System.out.println("\tNo doubles submitted");
}
System.out.println(words);
}
}
The ints and doubles get processed well, but im stuck in the strings. Any ideas on how to go about doing so? Thanks in advance!