Advertisement
Stan0033

Untitled

Jun 17th, 2021
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace apps
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. static int GetInput_Int() { return int.Parse(Console.ReadLine()); }
  11. //-----------------------------------------------------------------------------
  12. //-----------------------------------------------------------------------------
  13. //-----------------------------------------------------------------------------
  14. while (true)
  15. {
  16.  
  17. string input = Console.ReadLine();
  18. if (input == "END") { break; }
  19. else
  20. {
  21. Console.WriteLine($"{input} is {FindType(input)} type");
  22. }
  23.  
  24. }
  25.  
  26.  
  27. }
  28. //-----------------------------------------------------------------------------
  29. static string FindType(string input)
  30. {
  31. string type = string.Empty;
  32. if (input == "true" || input == "false")
  33. {
  34. type = "boolean";
  35. }
  36. else
  37. {
  38. if (input.Length==1) // if the input is oonly 1 character it could be only int or char
  39. {
  40. if (char.IsDigit(input[0])) { type = "integer"; } else { type = "character"; }
  41. }
  42. else
  43. { // else it could be int, double or string
  44. if(input.Count(char.IsDigit) > 0 && input.Count(char.IsLetter) == 0)
  45. {
  46. if (input.Contains(".")) { type = "floating point"; } else { type = "integer"; }
  47.  
  48. }
  49. if (input.Count(char.IsLetter) > 0) { type = "string"; }
  50.  
  51.  
  52. }
  53. }
  54.  
  55. return type;
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement