- 最後登錄
- 2023-6-24
- 在線時間
- 1 小時
- 註冊時間
- 2014-6-23
- 閱讀權限
- 20
- 精華
- 0
- UID
- 14550743
- 帖子
- 14
- 積分
- 16 點
- 潛水值
- 6360 米
| 本帖最後由 nightquiet813 於 2015-8-28 06:14 PM 編輯
使用畫面:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- while (true)
- {
- try
- {
- long m = 0;
- long n = 0;
- long t = 0;
- m = long.Parse(textBox1.Text);
- n = long.Parse(textBox2.Text);
- if (!(n > m))
- {
- throw new Exception();
- }
- if(radioButton1.Checked ==true)
- {
- for (long i = m ; i <=n ; i++)
- {
- t+=i;
- }
- }
- if (radioButton2.Checked == true)
- {
- for (long i = m; i <= n; i++)
- {
- if (i % 2 == 1)
- {
- t += i;
- }
- }
- }
- if (radioButton3.Checked == true)
- {
- for (long i = m; i <= n; i++)
- {
- if (i % 2 == 0)
- {
- t += i;
- }
- }
- }
- if (MessageBox.Show("總和為" + t ,"答案",MessageBoxButtons.OK,MessageBoxIcon.Information) == DialogResult.OK )
- {
- break;
- }
- }
- catch (Exception)
- {
- MessageBox.Show("輸入值或輸入型態錯誤","錯誤",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
- textBox1.Clear();
- textBox2.Clear();
- textBox1.Focus();
- break;
- }
- }
- }
- }
- }
複製代碼
... |
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊 |