-
Notifications
You must be signed in to change notification settings - Fork 0
/
1 - FizzBuzz sem condicionais.cs
57 lines (48 loc) · 1.35 KB
/
1 - FizzBuzz sem condicionais.cs
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
/*
Fizzbuzz sem if/switch/ternário
Fizzbuzz é uma função que recebe um número e retorna "fizz" se o número for divisível por 3,
"buzz" se for divisível por 5 e "fizzbuzz" se for divisível por 3 e 5. Se o número não for divisível
nem por 3 e nem por 5, retorna o número.
Faça a função fizzbuzz sem usar if, switch ou ternário
*/
using System;
namespace Logikoz.Desafios
{
class FizzBuzz
{
public static string Fizzbuzz(int value)
{
string[] a = new[] { "Fizz", "Buzz", "FizzBuzz", value.ToString() };
bool isFizz = value % 3 == 0;
bool isBuzz = value % 5 == 0;
int t = Convert.ToInt32(isFizz);
int g = Convert.ToInt32(isBuzz);
int? aux = null;
try
{
aux = 1 / t;
try
{
aux = 1 / g;
}
catch (ArithmeticException)
{
return a[0];
}
}
catch (ArithmeticException)
{
try
{
aux = 1 / g;
}
catch (ArithmeticException)
{
return a[3];
}
return a[1];
}
return a[2];
}
}
}