Skip to content

Commit d7389fc

Browse files
committed
Add new Algo
1 parent a49c7f0 commit d7389fc

File tree

5 files changed

+116
-0
lines changed

5 files changed

+116
-0
lines changed

Diff for: 01.Introduction/ColdNumber.java

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.util.*;
2+
3+
class ColdNumber{
4+
public static void main(String args[]){
5+
Scanner s = new Scanner(System.in);
6+
int t=1;
7+
int a = s.nextInt();
8+
if (a%2==0){
9+
t = (int)(a/2);
10+
}
11+
if (a%2!=0){
12+
t = (int)(a/2)+1;
13+
}
14+
if (a%t==0){
15+
System.out.println("Cold Number");
16+
}
17+
else{
18+
System.out.println("Not Cold Number");
19+
}
20+
}
21+
}

Diff for: 01.Introduction/HcfLcm.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.*;
2+
3+
class HcfLcm {
4+
public static void main(String args[]){
5+
int a = Integer.parseInt(args[0]);
6+
int b = Integer.parseInt(args[1]);
7+
int h = hcf(a,b);
8+
System.out.println(h);
9+
System.out.println((a*b)/h);
10+
}
11+
12+
public static int hcf(int a, int b) {
13+
while (a!=b) {
14+
if (a>b){
15+
a = a-b;
16+
}
17+
else{
18+
b = b-a;
19+
}
20+
}
21+
return a;
22+
}
23+
}

Diff for: 01.Introduction/IdAndShip.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.util.*;
2+
3+
class IdAndShip {
4+
public static void main(String args[]) {
5+
Scanner s = new Scanner(System.in);
6+
int t = s.nextInt();
7+
int i;
8+
char a;
9+
for (i=1; i<=t; i++){
10+
a = s.next().charAt(0);
11+
switch(a){
12+
case 'B':
13+
case 'b': System.out.println("Battleship");break;
14+
15+
case 'C':
16+
case 'c': System.out.println("Cruiser"); break;
17+
18+
case 'D':
19+
case 'd': System.out.println("Destroyer"); break;
20+
21+
case 'F':
22+
case 'f': System.out.println("Frigate"); break;
23+
24+
default: System.out.println("Enter Valid Choice");
25+
}
26+
}
27+
}
28+
}

Diff for: 01.Introduction/SineCosine.java

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

Diff for: Sorting algorithms/Insertion.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.util.*;
2+
3+
class Insertion {
4+
public static void main (String args[]) {
5+
Scanner s = new Scanner (System.in);
6+
System.out.println("Enter number of elements");
7+
int n = s.nextInt();
8+
int i;
9+
int a[] = new int[n];
10+
for (i=0;i<n;i++) {
11+
a[i] = s.nextInt();
12+
}
13+
insertion_sort(a,n);
14+
}
15+
16+
public static void insertion_sort(int[] a, int n){
17+
int i,j,k;
18+
for (j=1;j<n;j++) {
19+
k = a[j];
20+
i=j-1;
21+
while (i>-1 && a[i]>k) {
22+
a[i+1] = a[i];
23+
i--;
24+
}
25+
a[i+1] = k;
26+
}
27+
System.out.println("Sorted array");
28+
for (i=0;i<n;i++) {
29+
System.out.println(a[i]);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)