JasperHuyghe

Untitled

Mar 8th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. program.cs
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Oef3Teldezin
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Business z1 = new Business();
  15.             Console.WriteLine("Geef een zin");
  16.             Console.ForegroundColor = ConsoleColor.Red;
  17.             Console.WriteLine("Aantal woorden in de gegeven zin: " +z1.Aantalwoorden(Console.ReadLine()));
  18.             Console.ReadLine();
  19.         }
  20.     }
  21. }
  22.  
  23. Business.cs
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Linq;
  27. using System.Text;
  28. using System.Threading.Tasks;
  29.  
  30. namespace Oef3Teldezin
  31. {
  32.     class Business
  33.     {
  34.         public int Aantalwoorden(string pinvoer)
  35.         {
  36.             int aantal = 1;
  37.             for (int teller = 0; teller < pinvoer.Length; teller++)
  38.             {
  39.                 if (pinvoer[teller]==' ')
  40.                 {
  41.                     aantal += 1;
  42.                 }
  43.             }
  44.             return aantal;
  45.  
  46.         }
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment