Advertisement
nuggetin

asdas

Dec 13th, 2021
890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _12345
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             bool result = false;
  10.             while(!result){
  11.                 try
  12.                 {
  13.                     Console.WriteLine("Enter 6 a digit number e.g 123456");
  14.                     int n = int.Parse(Console.ReadLine());
  15.                     if (n.ToString().Length == 6)
  16.                     {
  17.                         if (int.Parse(n.ToString().Substring(0, (n.ToString().Length - 1))) % 7
  18.                             == int.Parse(n.ToString().Substring(n.ToString().Length - 1)))
  19.                         {
  20.                             Console.WriteLine("True");
  21.                         }
  22.                         else
  23.                         {
  24.                             Console.WriteLine("False");
  25.                         }
  26.                         result = true;
  27.                     }
  28.                     else { throw new Exception(); }
  29.                 }
  30.                 catch (Exception e)
  31.                 {
  32.                     Console.WriteLine("6 Digits only.");
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement