Advertisement
jkonova

Untitled

Sep 21st, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2.  
  3. namespace DataTypeFinder
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var input = Console.ReadLine();
  10.  
  11.             bool isFloatingPointNumber = false;
  12.             bool hasLetter = false;
  13.  
  14.             while (input != "END")
  15.             {
  16.                 if (input == "true" || input == "false")
  17.                 {
  18.                     Console.WriteLine($"{input} is boolean type");
  19.                 }
  20.                 for (int i = 0; i < input.Length; i++)
  21.                 {
  22.                     if (input[0] == 45 && i > 0 && (input[i] <= 48 || input[i] > 57))
  23.                     {
  24.                         hasLetter = true;
  25.                     }
  26.                     else
  27.                     {
  28.                         if (input[i] == 44 || input[i] == 46)
  29.                         {
  30.                             isFloatingPointNumber = true;
  31.                         }
  32.                     }
  33.                 }
  34.                 if (!hasLetter)
  35.                 {
  36.                     if (isFloatingPointNumber)
  37.                     {
  38.                         Console.WriteLine($"{input} is floating point type");
  39.                     }
  40.                     else
  41.                     {
  42.                         Console.WriteLine($"{input} is integer type");
  43.                     }
  44.                 }
  45.                 if (input.Length == 1)
  46.                 {
  47.                     Console.WriteLine($"{input} is character type");
  48.                 }
  49.                 else if (input.Length > 1)
  50.                 {
  51.                     Console.WriteLine($"{input} is string type");
  52.                 }
  53.                 input = Console.ReadLine();
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement