您好,登錄后才能下訂單哦!
1.輸入是數(shù)字
2.小數(shù)無奇偶性
3.奇偶性判斷 n%2==0 偶數(shù) 反之為奇數(shù)
因為是初學(xué)Asp.Net,頭文件using老是沒寫全。其實我還不知道那些要寫,那些不用寫上。 必須盡快學(xué)會
- using System;
- using System.Text;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- namespace WebApplication2
- {
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- private static int IsNumeric(string str) //接收一個string類型的參數(shù),保存到str里
- {
- char[] a=str.ToCharArray();;
- int i;
- if (str == null || str.Length == 0)
- //驗證這個參數(shù)是否為空
- return 0; //是,就返回False
- for(i=0;i<str.Length;i++)
- {
- if (a[i]=='.') //判斷是否為 0.1
- {
- return 2; //不是,就返回False
- }
- }
- ASCIIEncoding ascii = new ASCIIEncoding();//new ASCIIEncoding 的實例
- byte[] bytestr = ascii.GetBytes(str); //把string類型的參數(shù)保存到數(shù)組里
- foreach (byte c in bytestr) //遍歷這個數(shù)組里的內(nèi)容
- {
- if (c < 48 || c > 57) //判斷是否為數(shù)字
- {
- return 0; //不是,就返回False
- }
- }
- return 1; //是,就返回True
- }
- protected void TextBox1_TextChanged(object sender, EventArgs e)
- {
- int i = IsNumeric(TextBox1.Text);
- TextBox2.Text = i.ToString();
- if (i == 1)
- {
- int a = Int16.Parse(TextBox1.Text);
- if (a % 2 == 0) { TextBox2.Text = "偶數(shù)"; }
- else if (a % 2 != 0) { TextBox2.Text = "奇數(shù)"; }
- }
- else if (i == 0)
- TextBox2.Text = "輸入錯誤!";
- else if (i == 2)
- TextBox2.Text = "小數(shù)無奇偶性";
- }
- }
- }
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。