Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions BubbleSort.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
import java.lang.*;
public class BubbleSort{
public static void main(String arg[])
{

public class BubbleSort {
public static void main(String arg[]) {
int a[]={30,60,35,20,45,32,50};
System.out.println("Array Before Sorting");
for(int i=0;i<a.length;i++)
{
for(int i=0;i<a.length;i++) {
System.out.print(a[i]+" ");
}
System.out.println();
bubbleSort(a);
System.out.println("Array after sorting");
for(int i=0;i<a.length;i++)
{
for(int i=0;i<a.length;i++) {
System.out.print(a[i]+" ");
}
}
static void bubbleSort(int[] a){
static void bubbleSort(int[] a) {
int n = a.length;
int t = 0;
for(int i=0;i<n;i++)
{
for(int j=1;j<n-i;j++)
{
if(a[j-1]>a[j])
{
for(int i=0;i<n;i++) {
for(int j=1;j<n-i;j++) {
if(a[j-1]>a[j]) {
t = a[j-1];
a[j-1] = a[j];
a[j]= t;
}
}
}
}
}
}
15 changes: 6 additions & 9 deletions Echo.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
class Echo
{
public static void main(String args[])
{
for(int i=0;i<args.length;i++)
{
class Echo {
public static void main(String args[]) {
for(int i=0;i<args.length;i++) {
System.out.print(args[i]+" ");
System.out.println("\n");
}
System.exit(0);
}
System.exit(0);
}

}

32 changes: 17 additions & 15 deletions Fibonacci.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
class FibonacciExample1{
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;
System.out.print(n1+" "+n2);//printing 0 and 1

for(i=2;i<count;++i)//loop starts from 2 because 0 and 1 are already printed
{
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}

}}
class FibonacciSeries {
public static void main(String args[])
{
int n1=0,n2=1,n3,i,count=10;

//printing 0 and 1
System.out.print(n1+" "+n2);

//loop starts from 2 because 0 and 1 are already printed
for(i=2;i<count;++i) {
n3=n1+n2;
System.out.print(" "+n3);
n1=n2;
n2=n3;
}
}
}

14 changes: 6 additions & 8 deletions Harry.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class Harry
{
public static void main(String args[])
{
int i=0;
i=Integer.parseInt(args[0]);
System.out.println("The value of i in Integer is"+i);
class Harry {
public static void main(String args[]) {
int i = 0;
i = Integer.parseInt(args[0]);
System.out.println("The value of i in Integer is"+i);
}
}
}
52 changes: 19 additions & 33 deletions QuickSort.java
Original file line number Diff line number Diff line change
@@ -1,62 +1,48 @@
class QuickSort
{
public static void main(String[]args)
{
class QuickSort {
public static void main(String[]args) {
int a[]={10,75,-15,17,0,-2};
QSort(a,0,a.length-1);
System.out.println("Sorted Array : ");
System.out.print("[");
for(int i=0;i<a.length;i++)
{
if(i == a.length-1)
System.out.print(a[i]);
else
System.out.print(a[i] + ", ");
}
System.out.println("]");
System.out.print("[");
for(int i=0;i<a.length;i++) {
if(i == a.length-1)
System.out.print(a[i]);
else
System.out.print(a[i] + ", ")
}
System.out.println("]");
}

public static void QSort(int a[],int l,int h)
{
if(l<h)
{

public static void QSort(int a[],int l,int h) {
if(l<h) {
int loc=Partion(a,l,h);
QSort(a,l,loc-1);
QSort(a,loc+1,h);
}
}

public static int Partion(int a[],int l,int h)
{
public static int Partion(int a[],int l,int h) {
int pivot = a[l];
int start=l;
int end=h;int tmp;

while(start < end)
{
while(start<=h && a[start]<=pivot)
{
while(start < end) {
while(start<=h && a[start]<=pivot) {
start++;
}
while(a[end]>pivot)
{
while(a[end]>pivot) {
end--;
}
if(start<end)
{
if(start<end) {
tmp=a[start];
a[start]=a[end];
a[end]=tmp;


}

}


tmp=a[l];
a[l]=a[end];
a[end]=tmp;
return end;
}
}
}
38 changes: 15 additions & 23 deletions ShellSort.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
public class ShellSort
{
public static void main(String[] args)
{
public class ShellSort {
public static void main(String[] args) {
int a[]={25,-17,8,92,-21,0};

for(int gap=a.length/2;gap>0;gap/=2)
{

for(int i=gap;i<a.length;i++)
{
for(int gap=a.length/2;gap>0;gap/=2) {
for(int i=gap;i<a.length;i++) {
int tmp=a[i];
int j=i;

while(j>=gap &&a[j-gap]>tmp)
{
while(j>=gap &&a[j-gap]>tmp) {
a[j]=a[j-gap];
j-=gap;
}
a[j]=tmp;

}
}

System.out.println("Sorted Array : ");
System.out.print("[");
for(int i=0;i<a.length;i++)
{
if(i == a.length-1)
System.out.print(a[i]);
else
System.out.print(a[i] + ", ");
System.out.println("Sorted Array : ");
System.out.print("[");

for(int i=0;i<a.length;i++) {
if(i == a.length-1)
System.out.print(a[i]);
else
System.out.print(a[i] + ", ");
}
System.out.println("]");
}

}
}
41 changes: 41 additions & 0 deletions armstrongNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Program to determine whether the number is Armstrong number or not
public class Armstrong {
// Function to calculate x raised to the power y
int power(int x, long y) {
if( y == 0)
return 1;
if (y%2 == 0)
return power(x, y/2)*power(x, y/2);
return x*power(x, y/2)*power(x, y/2);
}

// Function to calculate order of the number
int order(int x) {
int n = 0;
while (x != 0) {
n++;
x = x/10;
}
return n;
}

boolean isArmstrong (int x) {
// Calling order function
int n = order(x);
int temp=x, sum=0;
while (temp!=0) {
int r = temp%10;
sum = sum + power(r,n);
temp = temp/10;
}
return (sum == x);
}

public static void main(String[] args) {
Armstrong ob = new Armstrong();
int x = 153;
System.out.println(ob.isArmstrong(x));
x = 1253;
System.out.println(ob.isArmstrong(x));
}
}