Mrgentledolphin

conta parole

Feb 9th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. import java.util.*;
  2. public class conta_parole {
  3. //non funziona se l'ultimo carattere è uno spazio
  4.     public static void main(String[] args) {
  5.         Scanner input = new Scanner (System.in);
  6.         String nome;
  7.         int parole=1;
  8.         System.out.println("inserire nome");
  9.         nome=input.nextLine();
  10.         for(int i=0;i<nome.length(); i++){
  11.             if(nome.charAt(i)==' ')
  12.                 parole++;
  13.         }
  14.         System.out.println("parole: "+parole);
  15.     }
  16.  
  17. }
Advertisement
Add Comment
Please, Sign In to add comment