vb.net回文 vb回文数代码

vb.net程序编写?

dim s1 as string

成都创新互联是专业的隆回网站建设公司,隆回接单;提供网站设计、网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行隆回网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

dim s2 as string

s1=textbox1.text

s2=StrReverse(s1)'翻转

if s1=s2 then

label1.text=

VB.NET 编程 关于回文数的题目。

在WinForm项目的窗体上添加一个按钮和文本框,然后把下面的代码粘贴上去就可以了。

Public Function lsH(ByVal n As String) As String

Dim s1 As String = ""

Dim s2 As String = ""

Dim i As Integer = 0

Dim j As Integer

If n.Length = 1 Then

Return ("是回文数")

Else

If Tell_JiOu(n.Length) = 1 Then

j = (n.Length + 1) / 2

s1 = Mid(n, 1, j)

Else

j = n.Length / 2 + 1

s1 = Mid(n, 1, j - 1)

End If

For i = n.Length To j Step -1

s2 = s2 + Mid(n, i, 1)

Next

If s1 = s2 Then

Return "是回文数"

Else

Return "不是回文数"

End If

End If

End Function

'判断一个整数的奇偶

Public Function Tell_JiOu(ByVal k As Integer) As Integer

If k Mod 2 = 0 Then

Return 2

Else

Return 1

End If

End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click

Button.Text = lsH(TextBox1.Text)

End Sub

VB.NET 编写函数过程IsH(n) 判断是否为回文数

你的i = Len(Str(a))会出问题。

If i 1 Then

Return True

End If

这个返回在if内部,当条件不满足将导致函数无返回。

以下代码仅供参考:

Function IsH(ByVal a As Long) As Boolean

Dim i As Long, j As Long, t As String

t = a.ToString

i = t.Length

Select Case i

Case 1

Return True

Case 2

If Mid(t, 1, 1) = Mid(t, 2, 1) Then Return True Else Return False

Case 3

If Mid(t, 1, 1) = Mid(t, 3, 1) Then Return True Else Return False

Case Else

For j = 1 To i \ 2

If Mid(t, j, 1) Mid(t, i - j + 1, 1) Then Return False

Next j

End Select

Return True

End Function


当前标题:vb.net回文 vb回文数代码
网站路径:http://myzitong.com/article/dopeejp.html