案例作业(一)

第三章       循环结构课后(一)
 
 
 
作业一:显示12生肖页面效果图
案例作业(一)_第1张图片
 
 
后台代码如下:
protected void Button1_Click(object sender, EventArgs e)
 
        string[] sheng = { " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " };
        Label1.Text = "";
        for (int i = 0; i < sheng.Length; i++)
        {
            if ((i + 0) % 4 == 0)
            {
                Label1.Text += "</br>" + "&nbsp;";
            }
            {
                Label1.Text += sheng[i].ToString() + "&nbsp;";
            }
        }
 
ctrl+F5 来验证:
 
作业二:两数之间能被3整除的所有数之和的效果图
 
try // 防止错误
        {
                double ma = Convert .ToDouble(TextBox1.Text);
                double fei = Convert .ToDouble(TextBox2.Text);
                double m;
                double a;
                double f = 0;
                if (ma > fei)
                {
                    m = ma;
                    a = fei;
                }
                else
                {
                    m = fei;
                    a = ma; // 设置无论ma fei 的大小关系如何大的数始终是m小的为a
                }
                for ( double sum = a; sum <=m; sum++) // 定义变量a<=sum<=m
                {
                    if (sum % 3 == 0) // 定义能被3整除的数
                    {
                        f += sum;
                        Label1.Text = f.ToString();
                    }
                }
            }
        catch
        {
            Label1.Text = " 请输入正确的字符" ;
        }
 
 
作业三:成绩排序页面效果图
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI. Page
{
    protected void Page_Load( object sender, EventArgs e)
    {
 
    }
    protected void Button1_Click( object sender, EventArgs e)
    {
        int [] chengji ={1,3,2,7};
        int max=0;
         for ( int i=0;i<chengji.Length-1;i++)
        {
            if (chengji[i]>chengji [i+1]) // 比较当元素前一个大于后一个时
            {
                max=chengji[i];
                chengji[i]=chengji[i+1];
                chengji[i+1]=max;
            }
          max=chengji[i+1]; // 将位置调换
        }
        Label1.Text=max.ToString(); // 输出最大值
 
 
    }
    protected void Button2_Click( object sender, EventArgs e)
    {
        Label2.Text = "" ; // 清空控件
        int [] chengji = { 1, 3, 2, 7 }; // 定义数组
        int max = 0;
        for ( int i = 0; i<chengji.Length; i++)
        {
            for ( int j = 1; j < chengji.Length - i; j++)
                if (chengji[j] < chengji[j - 1])
                {
                    max = chengji[j];
                    chengji[j] = chengji[j - 1];
                    chengji[j - 1] = max;
                }
        
        }
        foreach ( int j in chengji) // 循环
        Label2.Text += j.ToString();
    }
    protected void Button3_Click( object sender, EventArgs e)
    {
        Label3.Text = "" ;
        int [] liebiao = { 1, 5, 2, 6,3 };
        int min = 0;
        for ( int p = 0; p < liebiao.Length; p++)
        {
            for ( int s = 1; s < liebiao.Length - p; s++)
         
                if (liebiao[s] >liebiao[s - 1]) // 当后一个数大于前一个数时
                {
                    min = liebiao[s];
                    liebiao[s] = liebiao[s - 1];
                    liebiao[s - 1] = min;
                }
            }
        foreach ( int s in liebiao)
        Label3.Text += s.ToString()+ "&nbsp&nbsp;" ;
        }
    }
 
 
 
 
 
 

你可能感兴趣的:(职场,作业,休闲)