0
這是代碼。我基本上想要的是用戶輸入一個數字,按Enter鍵並讀取數字以便使用它。我不知道如果控制檯退出,因爲按下回車鍵,在最終用途console.read()
的或因其他原因輸入數據時如何不退出控制檯在Visual Basic中按Enter鍵
Sub CompruebaNumeroPrimo()
Console.Write("Función que comprueba si un nº es primo, introduce el nº")
Console.WriteLine()
Dim NumeroAComprobar As Integer = CType(Console.ReadLine(), Integer)
Dim RestosCero As Integer = 0
For Indice As Integer = 1 To NumeroAComprobar
If (NumeroAComprobar Mod Indice = 0) Then
RestosCero += 1
End If
Next Indice
If (RestosCero > 2) Then
Console.Write("No es primo")
Else
Console.Write("Es primo")
End If
Console.WriteLine()
End Sub