I am trying to figure out how to distiguish if the user input was a string or a int.
The out put i am looking for is
please enter a string: cat
please enter a string: dog
please enter a string: hamster
please enter a string: 1234
please enter a string: quit
Number of strings: 4
Average string length: 4.25
Number of possible words: 3
So am not sure how check to see if the user entered numbers and then avarage it up. Below is what i have so far
Thank you for your time.
import java.io.*;
import java.util.Scanner;
public class rad {
public static void main(String[] args) throws IOException {
{
Scanner in = new Scanner(System.in);
String input;
double counter = 1;
double totalLength = 0;
System.out.printf("Please enter a string:");
input = in.next();
while (!input.equals("quit")){
counter++;
int length = input.length();
totalLength += length;
System.out.printf("Please enter a string:");
input = in.next(); //waits for user to input more information
}//while
double finalCount = counter - 1;
System.out.printf("\nNumber of strings: %.1f\n", finalCount);
double averageLength = totalLength / finalCount;
System.out.printf("Average string length: %s\n total %s", averageLength, totalLength);
int numPossibleWords = 0;
System.out.printf("Number of possible words: %s", numPossibleWords);
}
}
}