-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment32_.java
More file actions
70 lines (45 loc) · 1.56 KB
/
Assignment32_.java
File metadata and controls
70 lines (45 loc) · 1.56 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package abhilash_Asignments;
//Using scanner class static and nonstatic lets do Addition,Substraction ,
//Multiplicaion division and modulus of 4 diff method.
import java.util.Scanner; //scanner class imported
public class Assignment32_ {
// Static method for addition
static int add(int a, int b) {
return a + b;
}
// Static method for subtraction
static int subtract(int a, int b)
{
return a - b;
}
// Non-static method for multiplication
int multiply (int a, int b)
{return a * b; }
// Non-static method for division
double divide(int a, int b)
{ return a / b; }
// Non-static method for modulus
public int modulus(int a, int b)
{ return a % b;}
public static void main(String[] args) // main method
{
Scanner scanner = new Scanner(System.in); // scanner class inside the main method
System.out.print("Enter the first number: ");
int a1 = scanner.nextInt(); // using scanner class int
System.out.print("Enter the second number: ");
int b1 = scanner.nextInt(); // using scanner class int
// Using static methods
int add = add(a1, b1);
int sub = subtract(a1, b1);
// Using non-static methods
Assignment32_ c1 = new Assignment32_(); // creating an object for class to access non static method
int a = c1.multiply(a1, b1);
double b = c1.divide(a1, b1);
int c = c1.modulus(a1, b1);
System.out.println("Addition: " + add); // implementation
System.out.println("Subtraction: " + sub);
System.out.println("Multiplication: " + a);
System.out.println("Division: " + b);
System.out.println("Modulus: " + c);
}
}