Visual Studio 2010旗舰版的vb.net版本18进制口诀表程序代码

Imports System

Public Class Form1

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim n, m, o As Integer
    Dim r1, s1, t1 As String
    Dim sb As New System.Text.StringBuilder() '用 StringBuilder 来构建显示字符串

    For n = 0 To 20
        For m = 0 To 20
            o = n + m

            '用函数将整数转换为基数为 18 的字符串
            r1 = IntToBaseString(n, 18)
            s1 = IntToBaseString(m, 18)
            t1 = IntToBaseString(o, 18)

            '构建显示字符串
            sb.AppendLine(r1 & " + " & s1 & " = " & t1)
        Next
    Next

    TextBox1.Text = sb.ToString() '一次性将构建好的字符串赋值给 TextBox1
End Sub

Private Function IntToBaseString(ByVal num As Integer, ByVal base As Integer) As String
    Dim buffer As New System.Text.StringBuilder(33)
    Dim i As Integer = 0
    Dim isNegative As Boolean = False

    '处理负数
    If num < 0 Then
        isNegative = True
        num = -num
    End If

    '转换为字符串
    Do
        Dim digit As Integer = num Mod base
        If digit < 10 Then
            buffer.Insert(0, ChrW(48 + digit))
        ElseIf digit < 18 Then
            buffer.Insert(0, ChrW(65 + digit - 10)) '10 到 17 用 A 到 H 表示
        End If
        num = num \ base
    Loop While num > 0

    '如果是负数,添加负号
    If isNegative Then
        buffer.Insert(0, "-")
    End If

    Return buffer.ToString()
End Function

End Class

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

EYYLTV

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值