Skip to content

Commit b86aa20

Browse files
authored
Merge pull request codec-akash#11 from Ashsakshi19/master
InsertionSort
2 parents c5e889a + cc718f2 commit b86aa20

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

ArmstrongNumber

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class ArmstrongNum {
2+
3+
public static void main(String[] args) {
4+
5+
int num = 370, number, temp, total = 0;
6+
7+
number = num;
8+
while (number != 0)
9+
{
10+
temp = number % 10;
11+
total = total + temp*temp*temp;
12+
number /= 10;
13+
}
14+
15+
if(total == num)
16+
System.out.println(num + " is an Armstrong number");
17+
else
18+
System.out.println(num + " is not an Armstrong number");
19+
}
20+
}

InsertionSort.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
import java.util.Scanner;
3+
4+
5+
public class InsertionSort
6+
{
7+
public static void sort( int arr[] )
8+
{
9+
int N = arr.length;
10+
int i, j, temp;
11+
for (i = 1; i< N; i++)
12+
{
13+
j = i;
14+
temp = arr[i];
15+
while (j > 0 && temp < arr[j-1])
16+
{
17+
arr[j] = arr[j-1];
18+
j = j-1;
19+
}
20+
arr[j] = temp;
21+
}
22+
}
23+
24+
public static void main(String[] args)
25+
{
26+
Scanner scan = new Scanner( System.in );
27+
System.out.println("Insertion Sort Test\n");
28+
int n, i;
29+
30+
System.out.println("Enter number of integer elements");
31+
n = scan.nextInt();
32+
33+
int arr[] = new int[ n ];
34+
35+
System.out.println("\nEnter "+ n +" integer elements");
36+
for (i = 0; i < n; i++)
37+
arr[i] = scan.nextInt();
38+
39+
sort(arr);
40+
41+
System.out.println("\nElements after sorting ");
42+
for (i = 0; i < n; i++)
43+
System.out.print(arr[i]+" ");
44+
System.out.println();
45+
}
46+
}

0 commit comments

Comments
 (0)