-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise4.cs
More file actions
128 lines (111 loc) · 3.7 KB
/
Exercise4.cs
File metadata and controls
128 lines (111 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercises4
{
class Program
{
static void Main(string[] args)
{
//enter whichever method you'd like to see here
}
static void Consecutive()
{
Console.WriteLine("Enter a few numbers separated by a hyphen.");
var input = Console.ReadLine();
var numbers = new List<int>();
foreach (var number in input.Split('-'))
{
numbers.Add(Convert.ToInt32(number));
}
numbers.Sort();
var isConsecutive = true;
for (int i = 1; i < numbers.Count; i++)
{
if (numbers[i] != numbers[i - 1] + 1)
isConsecutive = false;
break;
}
if (isConsecutive == true)
Console.WriteLine("Consecutive");
else
Console.WriteLine("Not Consecutive");
}
static void Duplicates()
{
Console.WriteLine("Enter a few numbers separated by a hyphen.");
var input = Console.ReadLine();
var numbers = new List<int>();
if (String.IsNullOrEmpty(input))
return;
else
foreach (var number in input.Split('-'))
{
numbers.Add(Convert.ToInt32(number));
}
var uniques = new List<int>();
var includesDuplicates = false;
foreach (var number in numbers)
{
if (!uniques.Contains(number))
{
uniques.Add(number);
}
else
{
includesDuplicates = true;
break;
}
}
if (includesDuplicates)
Console.WriteLine("Duplicate");
}
static void ValidTime()
{
Console.WriteLine("Enter a time value in the 24-hour time format (ex: 19:00)");
var input = Console.ReadLine();
if (String.IsNullOrEmpty(input))
Console.WriteLine("Invalid Time");
var time = new List<int>();
foreach (var number in input.Split(':'))
{
time.Add(Convert.ToInt32(number));
}
if ((time[0] >= 00 && time[0] <= 23) && ((time[1] >= 00 && time[1] <= 59)))
Console.WriteLine("Valid Time");
else
Console.WriteLine("Invalid Time");
}
static void PascalCase()
{
Console.WriteLine("Enter a few words separated by a space.");
var input = Console.ReadLine();
if (String.IsNullOrEmpty(input) || String.IsNullOrWhiteSpace(input))
{
Console.WriteLine("Invalid, try again");
return;
}
var output = "";
foreach (var word in input.Split(' '))
{
var wordWithPascalCase = char.ToUpper(word[0]) + word.ToLower().Substring(1);
output += wordWithPascalCase;
}
Console.WriteLine(output);
}
static void VowelCounter()
{
Console.WriteLine("Enter an English word");
var input = Console.ReadLine().ToLower();
var vowels = new List<char>(new char[]{'a','e','i','o','u'});
var counter = 0;
foreach (var character in input)
{
if (vowels.Contains(character))
counter++;
}
Console.WriteLine(counter);
}
}
}