-
Notifications
You must be signed in to change notification settings - Fork 0
/
Methods.java
56 lines (46 loc) · 1.82 KB
/
Methods.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javavideos;
/**
* This file is to serve as an example of how to use multiple methods in java.
* Feel free to customize to fit your needs
*/
public class Methods {
public static void main(String args[]){
//creates two local int variable, someNum and otherNum
int someNum = 12;
int otherNum = 2;
//calls the multimethod
multiMethod(someNum, otherNum);
}
//this is a method that will take two numbers as arguments and multiply them
//together and give the user the output
public static void multiMethod(int numberOne, int numberTwo){
//result variable to store the result
int result = 0;
//stores the difference that is returned from the returnMethod()
int difference = 0;
//calculate the result of the two arguments
result = numberOne * numberTwo;
//outputs the result to the user
System.out.println("Your result is " + result);
//gets the difference of the numbers from the returnMethod()
difference = returnMethod(result);
//outputs the difference to the user
System.out.println("Your difference is " + difference);
}
//this is a method with a return type that takes one arguement
public static int returnMethod(int aInteger){
//declares and integer to subtract from the argument that is passed
int sub = 1;
// a difference variable to store theresult
int diff = 0;
//calculates the difference
diff = aInteger - sub;
//returns the difference
return diff;
}
}