Aykon

TekensTellen

Mar 7th, 2023
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.53 KB | None | 0 0
  1. //Versie 1
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace TelTekens
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             //tel tekens zonder spaties
  15.  
  16.             //variabelen
  17.             string zin;
  18.             int aantal =0;
  19.  
  20.             //invoer
  21.             Console.WriteLine("Geef je zin in");
  22.             zin = Console.ReadLine();
  23.  
  24.             //verwerking
  25.             for (int teller = 0; teller < zin.Length; teller++)
  26.             {
  27.                 if (zin[teller] != ' ')
  28.                 {
  29.                     aantal++;
  30.                 }
  31.             }
  32.  
  33.             Console.WriteLine();
  34.             Console.WriteLine("Aantal tekens zonder spaties: " + aantal);
  35.             Console.ReadLine();
  36.         }
  37.     }
  38. }
  39.  
  40.  
  41. //Versie 2
  42. using System;
  43. using System.Collections.Generic;
  44. using System.Linq;
  45. using System.Text;
  46. using System.Threading.Tasks;
  47.  
  48. namespace TelTekensVersie2
  49. {
  50.     class Program
  51.     {
  52.         static void Main(string[] args)
  53.         {
  54.             //tel het aantal tekens zonder een ander, door de gebruiker op te geven teken
  55.  
  56.             //variabelen
  57.             string zin;
  58.             int aantal = 0;
  59.             char teken = ' ';
  60.  
  61.             //invoer
  62.             Console.WriteLine("Geef je zin in");
  63.             zin = Console.ReadLine();
  64.             Console.WriteLine("Kies een teken");
  65.             teken = Convert.ToChar(Console.ReadLine());
  66.  
  67.             //verwerking
  68.             for(int teller =0; teller<zin.Length; teller++)
  69.             {
  70.                 if (zin[teller] != teken);
  71.                 {
  72.                     aantal++;
  73.                 }
  74.             }
  75.  
  76.             Console.WriteLine("Aantal tekens zonder {0} is {1}",teken, aantal);
  77.  
  78.             Console.ReadLine();
  79.         }
  80.     }
  81. }
  82.  
  83.  
  84. //Versie 3
  85. using System;
  86. using System.Collections.Generic;
  87. using System.Linq;
  88. using System.Text;
  89. using System.Threading.Tasks;
  90.  
  91. namespace TelTekensVersie2
  92. {
  93.     class Program
  94.     {
  95.         static void Main(string[] args)
  96.         {
  97.             //tel het aantal tekens zonder een ander, door de gebruiker op te geven teken
  98.  
  99.             //variabelen
  100.             string zin;
  101.             int aantal = 0;
  102.             char teken = ' ';
  103.  
  104.             //invoer
  105.             Console.WriteLine("Geef je zin in");
  106.             zin = Console.ReadLine();
  107.             Console.WriteLine("Kies een teken");
  108.             teken = Convert.ToChar(Console.ReadLine());
  109.  
  110.             //verwerking
  111.             for(int teller =0; teller<zin.Length; teller++)
  112.             {
  113.                 if (zin[teller] != teken);
  114.                 {
  115.                     aantal++;
  116.                 }
  117.             }
  118.  
  119.             Console.WriteLine("Aantal tekens zonder {0} is {1}",teken, aantal);
  120.  
  121.             Console.ReadLine();
  122.         }
  123.     }
  124. }
  125.  
  126.  
  127. //Versie 4
  128. using System;
  129. using System.Collections.Generic;
  130. using System.Linq;
  131. using System.Text;
  132. using System.Threading.Tasks;
  133.  
  134. namespace TelTekensVerise4
  135. {
  136.     class Program
  137.     {
  138.         static void Main(string[] args)
  139.         {
  140.             //zelfde als versie 3, zorg voor een herhaling
  141.  
  142.             //tel het aantal tekens zonder een ander, door de gebruiker op te geven teken
  143.  
  144.             //variabelen
  145.             string zin;
  146.             int aantal = 0, aantalTekenZelf = 0;
  147.             string invoer = " ";
  148.  
  149.             //invoer
  150.             Console.WriteLine("Geef je zin in");
  151.             zin = Console.ReadLine();
  152.             Console.WriteLine("Kies een teken of 'stop'");
  153.             invoer = Console.ReadLine();
  154.  
  155.             //verwerking
  156.             while (invoer != "stop")
  157.             {
  158.                 char teken = Convert.ToChar(invoer);
  159.  
  160.                 for (int teller = 0; teller < zin.Length; teller++)
  161.             {
  162.                 if (zin[teller] != teken)
  163.                 {
  164.                     aantal++;
  165.                 }
  166.                 else
  167.                 {
  168.                     aantalTekenZelf++;
  169.                 }
  170.             }
  171.  
  172.             Console.WriteLine("Aantal tekens zonder {0} is {1}", teken, aantal);
  173.             Console.WriteLine("Het teken zelf komt {0} keer voor", aantalTekenZelf);
  174.             Console.WriteLine("Kies een teken of 'stop'");
  175.             invoer = Console.ReadLine();
  176.                 aantal = 0;
  177.                 aantalTekenZelf = 0;
  178.  
  179.             }
  180.  
  181.            
  182.         }
  183.     }
  184. }
  185.  
  186.  
  187. //Lagen
  188. //Klasse
  189. using System;
  190. using System.Collections.Generic;
  191. using System.Linq;
  192. using System.Text;
  193. using System.Threading.Tasks;
  194.  
  195. namespace TekensTellenLagen
  196. {
  197.     class Business
  198.     {
  199.         public int telZonderSpaties(string pinvoer)
  200.         {
  201.             int aantal = 0;
  202.             for (int teller= 0;  teller < pinvoer.Length; teller++)
  203.             {
  204.                 if (pinvoer[teller] != ' ')
  205.                 {
  206.                     aantal++;
  207.                 }
  208.             }
  209.             return aantal;
  210.         }
  211.     }
  212. }
  213.  
  214. //Program.cs
  215. using System;
  216. using System.Collections.Generic;
  217. using System.Linq;
  218. using System.Text;
  219. using System.Threading.Tasks;
  220.  
  221. namespace TekensTellenLagen
  222. {
  223.     class Program
  224.     {
  225.         static void Main(string[] args)
  226.         {
  227.             Business tellen = new Business();
  228.             Console.WriteLine("Geef je zin in");
  229.             string tekst = Console.ReadLine();
  230.             Console.WriteLine("Aantal tekens zonder spaties: {0}", tellen.telZonderSpaties(tekst));
  231.             Console.ReadLine();
  232.         }
  233.     }
  234. }
Advertisement
Add Comment
Please, Sign In to add comment