zoukankan      html  css  js  c++  java
  • 第三节 3练习1 简单

    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 _3练习1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string str_width = tb_width.Text;
                string str_height = tb_height.Text;
                //判断值是否有效
                int i1, i2, sum;
                if (!int.TryParse(str_width, out i1)) {
                    MessageBox.Show("宽为非整数!");
                    return;
                }
                if (!int.TryParse(str_height, out i2)) {
                    MessageBox.Show("高为非整数!");
                    return;
                }
                sum = i1 * i2;
                tb_sum.Text = Convert.ToString(sum);
    
    
            }
    
            private void button2_Click(object sender, EventArgs e)
            {
                string email = tb_email.Text;
                //进行字符串进行分析,然后放入数组中的
                //这里用数组的长度来判断该email是否有效
                string[] str = email.Split('@');
                if (str.Length != 2) {
                    MessageBox.Show("Email不合法!");
                    return;
                }
    
                tb_name.Text = str[0];
                tb_www.Text = str[1]; 
            }
    
            private void button3_Click(object sender, EventArgs e)
            {
                //求累加
                string str1 = tb_start.Text;
                string str2 = tb_end.Text;
                int i1, i2;
                if (!int.TryParse(str1, out i1)){
                    MessageBox.Show("第一个数值不是整数!");
                    return;
                }
                if (!int.TryParse(str2, out i2)) {
                    MessageBox.Show("第二个数值不是整数!");
                    return;
                }
                if (i2 <= i1) {
                    MessageBox.Show("第二个值不能小大第一个值!");
                    return;
                }
                int sum = 0;
                for (int i = i1; i <= i2; i++) {
                    sum += i;
                }
                tb_count.Text = Convert.ToString(sum);
            }
    
    
        }
    }
    

      

  • 相关阅读:
    POJ 1251 Jungle Roads
    1111 Online Map (30 分)
    1122 Hamiltonian Cycle (25 分)
    POJ 2560 Freckles
    1087 All Roads Lead to Rome (30 分)
    1072 Gas Station (30 分)
    1018 Public Bike Management (30 分)
    1030 Travel Plan (30 分)
    22. bootstrap组件#巨幕和旋转图标
    3. Spring配置文件
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2370605.html
Copyright © 2011-2022 走看看