Answer:
<em>import java.util.Scanner;</em>
<em>public class ANot {</em>
<em> public static void main(String[] args) {</em>
<em> Scanner in = new Scanner(System.in);</em>
<em> System.out.println("Please enter a string of words");</em>
<em> String n = in.nextLine();</em>
<em> int count = 0;</em>
<em> for (int i=0; i<n.length(); i++){</em>
<em> if((n.charAt(i) != '.') &&(n.charAt(i) != ',') && (n.charAt(i) != ' ')){</em>
<em> count++;</em>
<em> }</em>
<em> }</em>
<em> System.out.println(count);</em>
<em> }</em>
<em>}</em>
Explanation:
- Prompt User to input the string and assign to a variable
- SET count =0.
- Using a for loop iterate over the string
- if((n.charAt(i) != '.') &&(n.charAt(i) != ',') && (n.charAt(i) != ' ')) then count =count +1.
- PRINT count.