Advertisement
LePetitGlacon

FICHE 6 Exercice 9

Nov 18th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2.  
  3. namespace o
  4. {
  5.     class Program
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("phrase ?");
  10.             string phrase = Console.ReadLine();
  11.             string[] tabString = phrase.Split(' ');
  12.             char[] tabChar = phrase.ToCharArray();
  13.             int compteur = 1;
  14.            
  15.             //compter les mots
  16.             for (int i = 0;i != tabChar.Length;i++)
  17.             {
  18.                if (tabChar[i] == ' ')
  19.                 {
  20.                     compteur++;
  21.                 }
  22.             }
  23.            
  24.             Console.WriteLine("Il y a {0} mots\n",compteur);
  25.             foreach (string mot in tabString)
  26.             {
  27.                 Console.WriteLine(mot);
  28.             }
  29.              Console.ReadKey();
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement