- using ConsoleApp1;
- using System;//程式庫呼叫
- using System.ComponentModel.DataAnnotations;
- using System.Linq.Expressions;
- using ABC.qq;
- class Program//負責一部分工作的人
- {
- static void Main()//method ..Entry Point 程式進入點
- {
- try
- {
- int x1, x2;
- x1 = Convert.ToInt32(Console.ReadLine());
- x2 = Convert.ToInt32(Console.ReadLine());
- int tmp;
- if (x1 > x2)
- {
- tmp = x1;
- x1 = x2;
- x2 = tmp;
- }
- if (x1 <= 0 || x2 > 100)
- throw new ArgumentException();//使用指定的錯誤訊息。
- bool foundFactor;
- for(int n=Math.Max(x1,2); n<=x2;n++)
- {
- foundFactor = false;
- for(int k=2;k<n;k++)
- {
- if(n%k==0)
- {
- foundFactor = true;
- break;
- }
- }
- if(!foundFactor)
- {
- Console.WriteLine(n);
- }
- }
- }catch(Exception e)
- {
- Console.WriteLine(e.Message);
- Console.WriteLine("error");
- }
- }
- /*
- * ArgumentException是一個自訂「合法參數」的例外,
- * ArgumentException類別所接受的合法參數,是由程式設計師自行設定的。
- *
- * FormatException當參數格式不符合呼叫的方法的參數規範時引發的異常.
- */
- }
複製代碼 |