New to Java : Need help with my integers rules

Hi everyone,

I was unable to see the board last Java class so I have a quick/easy question. I was asked to write a basic program with mathematical expressions so I wrote the following:

_____________________________________

public class Assign01 {

public static void main(String[] args) {

// creating my int variables here

int num1=0,num2=0,sumvalue=0,diffvalue=0,productvalue= 0,quotvalue=0,remaindervalue=0;

Scanner sc = new Scanner(System.in);

// straight forward

System.out.println("Please choose your first number: ");

num1 = sc.nextInt();

System.out.println("Please choose your second number: ");

num2 = sc.nextInt();

// straight forward

sumvalue = num1+num2;

diffvalue = num1-num2;

productvalue = num1*num2;

quotvalue = num1/num2;

remaindervalue = num1%num2

_____________________________________

Under this I wrote "System.out.println ..." to write the answers and explain tips about math.

Can someone explain where can I add something like this?

______________________

int subtract(){

int result;

if (num1 > num2)

result = num1-num2;

else

result = num2-num1;

return result;

______________________

and something like this for division: "divide = if 15 divided by 0 = zero then return the value 0 as a result". Where would I add this in my program?

Any help/guidance would be greatly appreciated.

Regards,

MartinRR

Re: New to Java : Need help with my integers rules

Re: New to Java : Need help with my integers rules

Very nice! Thanks KevinWorkman.

Cheers,

Martin

Re: New to Java : Need help with my integers rules