Advertisement
Guest User

Untitled

a guest
Jan 16th, 2020
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Vacation
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string command = Console.ReadLine();
  10.  
  11.             while (command != "END")
  12.             {
  13.                 if (command.ToLower() == "true" || command.ToLower() == "false")
  14.                 {
  15.                     Console.WriteLine($"{command} is boolean type");
  16.                 }
  17.                 else if (command.Length == 1 && (command[0] < '0' || command[0] > '9'))
  18.                 {
  19.                     Console.WriteLine($"{command} is character type");
  20.                 }
  21.                 else
  22.                 {
  23.                     bool isString = false;
  24.                     bool isFloatingPoint = false;
  25.                     bool isInt = false;
  26.                     int dotCounter = 0;
  27.  
  28.                     for (int i = 0; i < command.Length; i++)
  29.                     {
  30.                         if ((i > 0 && command[i] == '-') || (i == 0 && command[i] == '.'))
  31.                         {
  32.                             isString = true;
  33.                         }
  34.                         else if ((command[i] >= '0' && command[i] <= '9') || command[i]=='-')
  35.                         {
  36.                             isInt = true;
  37.                         }
  38.                         else if (command[i] == '.')
  39.                         {
  40.                             dotCounter++;
  41.                             if (dotCounter == 1)
  42.                             {
  43.                                 isFloatingPoint = true;
  44.                             }
  45.                             else
  46.                             {
  47.                                 isString = true;
  48.                             }
  49.                         }
  50.                         else
  51.                         {
  52.                             isString = true;
  53.                         }
  54.                     }
  55.  
  56.                     if (isString)
  57.                     {
  58.                         Console.WriteLine($"{command} is string type");
  59.                     }
  60.                     else if (isInt && isFloatingPoint)
  61.                     {
  62.                         Console.WriteLine($"{command} is floating point type");
  63.                     }
  64.                     else
  65.                     {
  66.                         Console.WriteLine($"{command} is integer type");
  67.                     }
  68.                 }
  69.                 command = Console.ReadLine();
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement