Skip to content

Commit 4ac0d31

Browse files
committed
First commit
1 parent 55b7956 commit 4ac0d31

3 files changed

Lines changed: 126 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import java.util.Scanner;
2+
3+
public class AlgebraicOperations {
4+
public static void main(String args[]) {
5+
6+
//Declaring variables
7+
double n1,n2,res = 0;
8+
9+
System.out.println("Algebraic Operations of two Numbers\n---");
10+
Scanner scanner = new Scanner(System.in);
11+
12+
System.out.println("Enter the number 1: ");
13+
n1 = scanner.nextDouble();
14+
15+
System.out.println("Enter the number 2: ");
16+
n2 = scanner.nextDouble();
17+
18+
System.out.println("---\nEnter 1 for addition,\n2 for subtraction\n3 for multiplication\n4 for division");
19+
int operator = scanner.nextInt();
20+
21+
//Solving by if else loops
22+
if(operator==1) {
23+
res =n1+n2;
24+
}
25+
else if(operator==2) {
26+
res =n1-n2;
27+
}
28+
29+
else if(operator==3) {
30+
res =n1*n2;
31+
}
32+
33+
else if(operator==4) {
34+
res =n1/n2;
35+
}
36+
37+
else{
38+
System.out.println("Error!");
39+
end();
40+
}
41+
42+
System.out.println(res);
43+
end();
44+
scanner.close();
45+
}
46+
47+
static void end() {
48+
System.out.println("Enter Y to continue or any key to exit!");
49+
50+
Scanner getEndOption= new Scanner(System.in);
51+
String option = getEndOption.next();
52+
if(option.equalsIgnoreCase("Y")) {
53+
main(null);
54+
}
55+
else {
56+
System.out.println("The Program has ended. Please run the program again.");
57+
}
58+
getEndOption.close();
59+
}
60+
61+
62+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import java.util.Scanner;
2+
3+
public class AlgrebraicOperationsSwitchCase {
4+
public static void main(String args[]) {
5+
6+
//Declaring variables
7+
double n1,n2,res = 0;
8+
9+
System.out.println("Algebraic Operations of two Numbers with Switch Case Loop\n---");
10+
Scanner scanner = new Scanner(System.in);
11+
12+
System.out.println("Enter the number 1: ");
13+
n1 = scanner.nextDouble();
14+
15+
System.out.println("Enter the number 2: ");
16+
n2 = scanner.nextDouble();
17+
18+
System.out.println("---\nEnter 1 for addition or\n2 for subtraction or\n3 for multiplication or\n4 for division");
19+
int operator = scanner.nextInt();
20+
21+
//Solving by switch case loop for simpler code.
22+
switch(operator) {
23+
case 1:
24+
res = n1+n2;
25+
break;
26+
case 2:
27+
res = n1-n2;
28+
break;
29+
case 3:
30+
res = n1*n2;
31+
break;
32+
case 4:
33+
res = n1/n2;
34+
break;
35+
default:
36+
System.out.println("You have chosen a wrong option.\nPlease choose from the above given options.");
37+
end();
38+
}
39+
System.out.println(res);
40+
end();
41+
scanner.close();
42+
}
43+
44+
static void end() {
45+
System.out.println("---\nEnter Y to continue or any key to exit!");
46+
47+
Scanner getEndOption= new Scanner(System.in);
48+
String option = getEndOption.next();
49+
if(option.equalsIgnoreCase("Y")) {
50+
main(null);
51+
}
52+
else {
53+
System.out.println("The Program has ended. Please run the program again.");
54+
}
55+
getEndOption.close();
56+
}
57+
58+
}
59+

Basic-Java/HelloWorld.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class HelloWorld{
2+
public static void main(String[] args) {
3+
System.out.println("Hello World!!\nI'm learning Java.");
4+
}
5+
}

0 commit comments

Comments
 (0)