Skip to content

Commit a49c7f0

Browse files
committedJul 29, 2018
Initial commit
0 parents  commit a49c7f0

9 files changed

+177
-0
lines changed
 

Diff for: ‎.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*

Diff for: ‎01.Introduction/BasicCalculator.java

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import java.util.Scanner;
2+
3+
public class BasicCalculator{
4+
public static void main(String args[]) {
5+
Scanner sc = new Scanner(System.in);
6+
if(!sc.hasNextDouble()){
7+
System.out.println("Invalid input");
8+
return;
9+
}
10+
11+
double a = sc.nextDouble();
12+
13+
if(!sc.hasNext()){
14+
System.out.println("Invalid input");
15+
return;
16+
}
17+
18+
char o = sc.next().trim().charAt(0);
19+
20+
21+
if(!sc.hasNextDouble()){
22+
System.out.println("Invalid input");
23+
return;
24+
}
25+
26+
double b = sc.nextDouble();
27+
28+
switch(o){
29+
case '+':
30+
System.out.println(a+b);
31+
break;
32+
case '-':
33+
System.out.println(a-b);
34+
break;
35+
case '*':
36+
System.out.println(a*b);
37+
break;
38+
case '/':
39+
System.out.println(a/b);
40+
break;
41+
case '%':
42+
System.out.println(a%b);
43+
break;
44+
default:
45+
System.out.println("Invalid input");
46+
}
47+
}
48+
}

Diff for: ‎01.Introduction/BasicCalculatorArgv.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.util.Scanner;
2+
3+
class BasicCalculatorArgv {
4+
public static void main(String args[]) {
5+
if(args.length != 3) {
6+
System.out.println("Invalid input");
7+
return;
8+
}
9+
10+
try {
11+
12+
double a = Double.parseDouble(args[0]);
13+
14+
char op = args[1].charAt(0);
15+
16+
double b = Double.parseDouble(args[2]);
17+
18+
switch(op) {
19+
case '+':
20+
System.out.println(a + b);
21+
break;
22+
case '-':
23+
System.out.println(a - b);
24+
break;
25+
case '*':
26+
System.out.println(a * b);
27+
break;
28+
case '/':
29+
System.out.println(a / b);
30+
break;
31+
case '%':
32+
System.out.println(a % b);
33+
break;
34+
default:
35+
System.out.println("Invalid input");
36+
break;
37+
}
38+
} catch(NumberFormatException ex) {
39+
System.out.println("Invalid input");
40+
}
41+
}
42+
}

Diff for: ‎01.Introduction/HelloMe.java

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import java.util.*;
2+
3+
public class HelloMe {
4+
public static void main(String args[]){
5+
Scanner sc = new Scanner(System.in);
6+
String s = sc.nextLine();
7+
System.out.println("Hello "+s);
8+
}
9+
}

Diff for: ‎01.Introduction/HelloMeFromArgs.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.util.*;
2+
3+
public class HelloMeFromArgs {
4+
public static void main(String args[]){
5+
int i;
6+
for (i=0;i<args.length;i++){
7+
System.out.println("Hello "+args[i]);
8+
}
9+
}
10+
}

Diff for: ‎01.Introduction/HelloMeFromEnvVars.java

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java.util.*;
2+
3+
public class HelloMeFromEnvVars {
4+
public static void main(String args[]){
5+
System.out.println("Hello " + System.getenv("MY_NAME"));
6+
}
7+
}

Diff for: ‎01.Introduction/HelloWorld.java

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import java.util.*;
2+
3+
public class HelloWorld {
4+
public static void main(String args[]){
5+
System.out.println("Hello World");
6+
}
7+
}

Diff for: ‎01.Introduction/MultiplesOfThreeOrFive.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.*;
2+
3+
class MultiplesOfThreeOrFive {
4+
public static void main(String args[]){
5+
Scanner s = new Scanner(System.in);
6+
int i,sum=0;
7+
int a = s.nextInt();
8+
for (i=1;i<a;i++){
9+
if (i%3==0 || i%5==0){
10+
sum+=i;
11+
12+
}
13+
14+
}
15+
System.out.print(sum);
16+
}
17+
}

Diff for: ‎01.Introduction/SumOfNumbers.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.util.*;
2+
3+
class SumOfNumbers {
4+
public static void main(String args[]){
5+
Scanner s = new Scanner(System.in);
6+
int i,sum=0;
7+
int a = s.nextInt();
8+
for (i=1;i<=a;i++){
9+
sum+=i;
10+
}
11+
System.out.println(sum);
12+
13+
}
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.