Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Versie 1
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TelTekens
- {
- class Program
- {
- static void Main(string[] args)
- {
- //tel tekens zonder spaties
- //variabelen
- string zin;
- int aantal =0;
- //invoer
- Console.WriteLine("Geef je zin in");
- zin = Console.ReadLine();
- //verwerking
- for (int teller = 0; teller < zin.Length; teller++)
- {
- if (zin[teller] != ' ')
- {
- aantal++;
- }
- }
- Console.WriteLine();
- Console.WriteLine("Aantal tekens zonder spaties: " + aantal);
- Console.ReadLine();
- }
- }
- }
- //Versie 2
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TelTekensVersie2
- {
- class Program
- {
- static void Main(string[] args)
- {
- //tel het aantal tekens zonder een ander, door de gebruiker op te geven teken
- //variabelen
- string zin;
- int aantal = 0;
- char teken = ' ';
- //invoer
- Console.WriteLine("Geef je zin in");
- zin = Console.ReadLine();
- Console.WriteLine("Kies een teken");
- teken = Convert.ToChar(Console.ReadLine());
- //verwerking
- for(int teller =0; teller<zin.Length; teller++)
- {
- if (zin[teller] != teken);
- {
- aantal++;
- }
- }
- Console.WriteLine("Aantal tekens zonder {0} is {1}",teken, aantal);
- Console.ReadLine();
- }
- }
- }
- //Versie 3
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TelTekensVersie2
- {
- class Program
- {
- static void Main(string[] args)
- {
- //tel het aantal tekens zonder een ander, door de gebruiker op te geven teken
- //variabelen
- string zin;
- int aantal = 0;
- char teken = ' ';
- //invoer
- Console.WriteLine("Geef je zin in");
- zin = Console.ReadLine();
- Console.WriteLine("Kies een teken");
- teken = Convert.ToChar(Console.ReadLine());
- //verwerking
- for(int teller =0; teller<zin.Length; teller++)
- {
- if (zin[teller] != teken);
- {
- aantal++;
- }
- }
- Console.WriteLine("Aantal tekens zonder {0} is {1}",teken, aantal);
- Console.ReadLine();
- }
- }
- }
- //Versie 4
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TelTekensVerise4
- {
- class Program
- {
- static void Main(string[] args)
- {
- //zelfde als versie 3, zorg voor een herhaling
- //tel het aantal tekens zonder een ander, door de gebruiker op te geven teken
- //variabelen
- string zin;
- int aantal = 0, aantalTekenZelf = 0;
- string invoer = " ";
- //invoer
- Console.WriteLine("Geef je zin in");
- zin = Console.ReadLine();
- Console.WriteLine("Kies een teken of 'stop'");
- invoer = Console.ReadLine();
- //verwerking
- while (invoer != "stop")
- {
- char teken = Convert.ToChar(invoer);
- for (int teller = 0; teller < zin.Length; teller++)
- {
- if (zin[teller] != teken)
- {
- aantal++;
- }
- else
- {
- aantalTekenZelf++;
- }
- }
- Console.WriteLine("Aantal tekens zonder {0} is {1}", teken, aantal);
- Console.WriteLine("Het teken zelf komt {0} keer voor", aantalTekenZelf);
- Console.WriteLine("Kies een teken of 'stop'");
- invoer = Console.ReadLine();
- aantal = 0;
- aantalTekenZelf = 0;
- }
- }
- }
- }
- //Lagen
- //Klasse
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TekensTellenLagen
- {
- class Business
- {
- public int telZonderSpaties(string pinvoer)
- {
- int aantal = 0;
- for (int teller= 0; teller < pinvoer.Length; teller++)
- {
- if (pinvoer[teller] != ' ')
- {
- aantal++;
- }
- }
- return aantal;
- }
- }
- }
- //Program.cs
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TekensTellenLagen
- {
- class Program
- {
- static void Main(string[] args)
- {
- Business tellen = new Business();
- Console.WriteLine("Geef je zin in");
- string tekst = Console.ReadLine();
- Console.WriteLine("Aantal tekens zonder spaties: {0}", tellen.telZonderSpaties(tekst));
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment