Skip to content
Open
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
32 changes: 32 additions & 0 deletions Java/BubbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Scanner;
public class BubbleSort
{
public static void main(String[] args)
{
int i, j, x;
Scanner s = new Scanner(System.in);
System.out.print("Enter the size of the array : ");
int n = s.nextInt();
int[] array = new int[n];
System.out.print("Enter the Elements : ");
for(i=0; i<n; i++)
{
array[i] = s.nextInt();
}
for(i=0; i<(n-1); i++)
{
for(j=0; j<(n-i-1); j++)
{
if(array[j]>array[j+1])
{
x = array[j];
array[j] = array[j+1];
array[j+1] = x;
}
}
}
System.out.println("The sorted array is:");
for(i=0; i<n; i++)
System.out.print(array[i]+ " ");
}
}
31 changes: 31 additions & 0 deletions Java/LinearSearch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.Scanner;
public class LinearSearch
{
public static void main(String[] args)
{
int i, num, pos=0;
Scanner s = new Scanner(System.in);
System.out.print("Enter the size of the array : ");
int n = s.nextInt();
int[] arr = new int[n];
System.out.print("Enter the Values: ");
for(i=0; i<n; i++)
arr[i] = s.nextInt();

System.out.print("Enter the value to Search: ");
num = s.nextInt();

for(i=0; i<10; i++)
{
if(num==arr[i])
{
pos = i+1;
break;
}
}
if(pos==0)
System.out.println("\nThe value is not found!");
else
System.out.println("\nThe element is found at position: " +pos);
}
}
15 changes: 15 additions & 0 deletions Java/StarPattern.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class StarPattern
{
public static void main(String args[])
{
int i, j, row=6;
for(i=0; i<row; i++)
{
for(j=0; j<=i; j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}