Hi, I'm trying to create a program that reads in a line of text. For some reasons, when I try to run the program, "Your input has ---- non-blank characters." comes up under every words. I want it to just come up once at the end. Any help will be appreciated. Thank you!
import java.util.*;
public class WordsInStrings{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
String s = scan.nextLine();
String[] words = s.split(" ");
for(int i=0; i<words.length; i++){
System.out.println(words[i]);
int count=0;
for(int a=0; a<words.length; a++){
count=words[a].length()+count;
}
System.out.println("Your input has " + count + " non-blank characters.");
}
}
}