Aykon

Oef3p24

Mar 8th, 2023
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. //Business.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 Oef3p24
  9. {
  10.     class Business
  11.     {
  12.         public int telWoorden(string zin)
  13.         {
  14.             int aantal = 1;
  15.             for(int teller = 0; teller < zin.Length; teller++)
  16.             {
  17.                 if(zin[teller]==' ')
  18.                 {
  19.                     aantal += 1;
  20.                 }
  21.             }
  22.             return aantal;
  23.         }
  24.     }
  25. }
  26.  
  27. //Program.cs
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Linq;
  31. using System.Text;
  32. using System.Threading.Tasks;
  33.  
  34. namespace Oef3p24
  35. {
  36.     class Program
  37.     {
  38.         static void Main(string[] args)
  39.         {
  40.             Business rekenen = new Business();
  41.            
  42.             Console.WriteLine("Schrijf een zin.");
  43.             rekenen.Zin = Console.ReadLine();
  44.  
  45.             Console.ForegroundColor = ConsoleColor.Green;
  46.             Console.WriteLine("Het aantal woorden in deze zin: " + rekenen.telWoorden(rekenen.Zin));
  47.  
  48.             Console.ReadLine();
  49.         }
  50.     }
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment