Skip to content

Commit b377d17

Browse files
BryzzBryzz
Bryzz
authored and
Bryzz
committed
performs basic arithmetic operations. closes DSC-UB#3
1 parent 3ff17c6 commit b377d17

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

resources/Arithmetic2/Arithmetic2.iml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
12+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.bryzz.dsc.arithmetic2;
2+
3+
import java.util.Scanner;
4+
import java.math.*;
5+
6+
class Arithmetic2 {
7+
8+
private static Scanner scanner = new Scanner(System.in);
9+
public static void main(String[] args) {
10+
System.out.println("Enter two numbers: ");
11+
int x = scanner.nextInt();
12+
int y = scanner.nextInt();
13+
14+
int sum = x + y;
15+
int dif = x - y;
16+
if(dif<0) {
17+
dif = y - x;
18+
}
19+
int pxt = x*y;
20+
int div = x/y;
21+
if(x == 0 ) {
22+
div = 0;
23+
}
24+
if(y == 0 ) {
25+
div = 0;
26+
}
27+
if(div < 1 ) {
28+
div = y/x;
29+
}
30+
31+
System.out.printf("\n\nSum = %d\nDifference = %d\nProduct = %d\nQuotient = %d", sum, dif, pxt, div);
32+
33+
34+
}
35+
}
36+
37+
/*
38+
(Arithmetic) Write an application that asks the user to enter two integers, obtains them
39+
from the user and prints their sum, product, difference and quotient (division).
40+
41+
Note that you should request a PR to this repo an your code will be merge in a branch with your name.
42+
Also, the name of your file should be arithmetic2-15.java*/

0 commit comments

Comments
 (0)