vb程式設計題在文字框1中輸入整數n判斷其能否

時間 2021-10-14 21:22:52

1樓:

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();}

2樓:匿名使用者

在窗體新增一個文字框和一個標籤和一個按鈕

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

3樓:匿名使用者

你新建一個窗體,上面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

4樓:喻元愷

_partial class form1

inherits system.windows.forms.form

'form 重寫 dispose,以清理元件列表。

_protected overrides sub dispose(byval disposing as boolean)

tryif 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

j**a程式設計,鍵盤輸入一個整數,判斷能否被5和6整除,再判斷能否被5或6整除?

vb程式設計題:單擊窗體,在窗體上顯示1~200之間既能被5整除又能被7整除的數的和

5樓:匿名使用者

private sub form_click()dim i as long, a as longa = 0

for i = 1 to 200

if i mod 5 = 0 and i mod 7 = 0 then

print i

a = a + i

end if

next

print "以上是同時被5和7整除的數,和=" & aend sub

6樓:精樸電池

' 單擊窗體函式裡面的**:

dim i as integer ' 從1~200dim count as integer ' 儲存所求的和for i=1 to 200

if (i mod 5 = 0) and (i mod 7 = 0) then

count = count + i

end if

next i

7樓:

for迴圈1到200,執行除5為ture再除7 ,ture就壘加到變數裡。

**就不給了,很簡單。

vb程式設計題在文字框tet1中輸入正整數單擊

下面是簡單實現,需要帶入引數是大於等於1的正數 自己防呆 private sub command1 click 呼叫例項dim str as string msgbox return str 5 end sub private function return str number as intege...

VB中如何輸入文字框文字輸入字元,在這字元後加上

private sub text1 change if len text1.text 4 then text1.text text1.text end sub 我精心寫了一段哦!現在針對的是text1這個控制元件只需要放一個text1控制元件在窗體上在複製這段 貼上執行就可以了。我想了3種方法,一個...

剛學vb在文字框中輸入字元,判斷是字母還是數字字元或者其他字元我寫的有問題應該怎麼改

s是變數,不該打引號。下面是用選擇語句來處理,可能比較清晰點。private sub command1 click dim s as string s text1 if len s 1 then select case s case a to z a to z msgbox 字母 case 0 to...