VB:编程题~~在文本框1中输入一个整数n,判断其能否同时被5和7整除……

2024-12-15 01:18:10
推荐回答(4个)
回答1:

你新建一个窗体,上面text、label、command控件各一个
Private Sub Command1_Click()
If Not IsNumeric(Text1.Text) Then Exit Sub
If Val(Text1.Text) Mod 5 = 0 And Val(Text1.Text) Mod 7 = 0 Then
Label1.Caption = Text1.Text & "能同时被5和7 整除"
Else
Label1.Caption = Text1.Text & "不能同时被5和7 整除"
End If
End Sub

回答2:

Console.Writeline("请输入一个整数:");
int n;
n=int.Parse(Console.ReadLine());
if(n%5==0&&n%7==0)

Console.WriteLine(n+"能够同时被5和7整除");
Console.Read();

elsew

Console.WriteLine(n+"不能够同时被5和7整除");
Console.Read();

回答3:

_
Partial Class Form1
Inherits System.Windows.Forms.Form

'Form 重写 Dispose,以清理组件列表。
_
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改它。
'不要使用代码编辑器修改它。
_
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.Label2 = New System.Windows.Forms.Label
Me.Label1 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(26, 82)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(75, 23)
Me.Button1.TabIndex = 0
Me.Button1.Tag = ""
Me.Button1.Text = "开始判读"
Me.Button1.UseVisualStyleBackColor = True
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(115, 28)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(159, 21)
Me.TextBox1.TabIndex = 2
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(129, 87)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(65, 12)
Me.Label2.TabIndex = 3
Me.Label2.Text = "判读结果:"
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(12, 31)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(89, 12)
Me.Label1.TabIndex = 3
Me.Label1.Text = "请输入一个数字"
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 12.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(360, 138)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label

End Class

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
If Me.TextBox1.Text.Trim() <> String.Empty Then

i = CInt(Me.TextBox1.Text.Trim())
If i Mod 5 = 0 And i Mod 7 = 0 Then
Me.Label2.Text = "判读结果:" + i.ToString() + "能够被 5 和 7 同时整除"
Else
Me.Label2.Text = "判读结果:" + i.ToString() + "不能够被 5 和 7 同时整除"
End If
End If
End Sub
End Class

回答4:

在窗体添加一个文本框和一个标签和一个按钮

Private Sub Command1_Click()
If Val(Text1.Text) Mod 5 = 0 And Val(Text1.Text) Mod 7 = 0 Then
Label1.Caption = Text1.Text & "能同时被5和7整除"
Else
Label1.Caption = Text1.Text & "不能同时被5和7整除"
End If
End Sub