Methods

1.define a method, which take 2 int number as parameters 

as method body, print   xx+xx=xx

first two xx are the value for 2 parameters , the last xx is the result of those number plus together

sample 1:

call method:    methodName(4,6)

print: 4+6=10

 

sample 2:

call method:    methodName(101,29)

print:101+29=130

 

2.define a methods,which take 2 int number  and a String as parameters 

as method body, print    xx ? xx = xx           

? is one of +, -, *, /, %

first two xx are the value for 2 int parameters , and ? is a operator which saved in that String parameter, the the last xx is the result of those number do the operation

sample 1:

call method:    methodName(4,6,"+")

print:   4+6=10

sample 2:

call method:    methodName(101,29,"-")

print:  101-29=72

sample 3:

call method:    methodName(33,3,"/")

print:  33/3=11

 

posted @ 2024-03-22 13:25  派若多克斯  阅读(78)  评论(0)    收藏  举报