VB如果数字是整数然后写它否则什么都不显示,我该怎么办?
问题描述:
我有这个...VB如果数字是整数然后写它否则什么都不显示,我该怎么办?
Dim x As Integer
Dim isn As Decimal
Dim fsn As Decimal
Dim inc As Decimal
For m = isn To fsn Step inc
Dim r As String = x * m
If r.Contains(".") Then
Else
Console.WriteLine(r)
End If
Next
Console.ReadLine()
...但该方案只是什么也不做......我该怎么办?请帮帮我!!
答
使用console.ReadLine
从用户
Sub Main()
Dim x As Integer = Console.ReadLine
Dim isn As Decimal = Console.ReadLine
Dim fsn As Decimal = Console.ReadLine
Dim inc As Decimal = Console.ReadLine
For m = isn To fsn Step inc
Dim r As Double = x * m
Dim r_string As String = r.ToString
If r_string.Contains(".") Then
Else
Console.WriteLine(r)
End If
Next
Console.ReadLine()
End Sub
答
有很多种方法来实现这一获得价值,我在我的代码来实现这一以及注释掉其他验证。
Dim x As Integer
Dim isn As Decimal
Dim fsn As Decimal
Dim inc As Decimal
For m = isn To fsn Step inc
Dim r As String = x * m
If Not r = int(r) Then 'If IsNumeric(r) = true AndAlso r.ToString().Contains(".") = true OrElse Math.Floor(value) = Math.Ceiling(value) OrElse Integer.TryParse(number, output) Then
Else
Console.WriteLine(r)
End If
Next
Console.ReadLine()
你一定要给出'x','isn','fsn','INC' – Subaz