Vb.net 使用while循环(VB)反转数字字符串
我对VB编程还比较陌生,我试图通过在代码底部使用while循环来反转变量“binary”中的数字字符串,但是当程序运行时,我得到一个System.IndexOutOfRangeException错误。要解决此问题,我需要做哪些更改? 谢谢Vb.net 使用while循环(VB)反转数字字符串,vb.net,Vb.net,我对VB编程还比较陌生,我试图通过在代码底部使用while循环来反转变量“binary”中的数字字符串,但是当程序运行时,我得到一个System.IndexOutOfRangeException错误。要解决此问题,我需要做哪些更改? 谢谢 Module Module1 Sub Main() Dim denary As Integer Dim binary As String = " " Dim x As Integer
Module Module1
Sub Main()
Dim denary As Integer
Dim binary As String = " "
Dim x As Integer
Dim y As Integer = 0
Console.WriteLine("What is the denary number?") 'Asks the user what number denary number they want converted
denary = Console.Read()
While denary > 0 'Calculates the binary number, but reversed
If denary Mod 2 = 0 Then
binary = binary + "0"
denary = denary / 2
Else
binary = binary + "1"
denary = denary / 2
End If
End While
Console.WriteLine("The binary equivalent is:" & binary) 'Prints the binary number in reverse
Console.ReadLine()
x = Len(binary)
While x > 0
Console.WriteLine(binary(x)) 'Print the correct binary equivalent (Not working)
Console.ReadLine()
x = x - 1
End While
End Sub
End Module
数组索引从0开始,因此最后一个索引总是比数组长度小1:
x = Len(binary) - 1
While x >= 0
'...
这是一个关于调试的大问题:断点、监视变量等。请阅读并接受