Private Sub Form1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
Dim n = e.KeyChar
If IsNumeric(n) Then
If Val(n) = 0 Then
e.Handled = True
End If
Dim result As Integer
Dim resultStr = String.Empty
For i = 1 To Val(n)
If i = Val(n) Then
resultStr += i.ToString + "^3="
Else
resultStr += i.ToString + "^3+"
End If
result += i ^ 3
Next
Console.Write(resultStr)
Console.Write(result.ToString + vbNewLine)
End If
End Sub
温馨提示:答案为网友推荐,仅供参考