Skip to content

HacktoberFest-2022 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
dd53cef
An optimized version of Bubble Sort
Sparsh225 Oct 1, 2022
c53a6ed
adding time complexity
Sparsh225 Oct 1, 2022
e2e3111
optimize sort
Sparsh225 Oct 1, 2022
6f98478
Merge branch 'ajitkumar1264:main' into updatedalgo
Sparsh225 Oct 1, 2022
09a3d70
shell_sort code
ajitkumar1264 Oct 1, 2022
e334644
Merge pull request #33 from Annex5061/main
ajitkumar1264 Oct 1, 2022
7542c1e
Add files via upload
dharmanshu1921 Oct 1, 2022
82dbfe3
Radix Sort
itssubhamroy23 Oct 1, 2022
7bb89b2
Create Inheritance.java
MeetVaishnav23 Oct 1, 2022
1c6fcbc
Create FactorialProgram.java
MeetVaishnav23 Oct 1, 2022
893135d
Create Electricitybill.java
MeetVaishnav23 Oct 1, 2022
aefb1b4
Please add my code to your repository
Oct 1, 2022
e610f6c
count sort program added
Saurav-Sutaria Oct 1, 2022
1df449a
Java Substring
anurag-compile Oct 1, 2022
6b9e113
Reverse words in string code in java
shwetacharde Oct 1, 2022
fe7af61
Bubblesort Algo
shubhamsingla807 Oct 1, 2022
c4763de
Create Reverse a Number using a while loop.java
SuvojitDev Oct 1, 2022
a2b0105
GCD
Bhumi54321 Oct 1, 2022
e098222
Transpose_of_Matrix.java
dhirenkokal Oct 1, 2022
d34177b
Counting Sort Algo
Shakshi2822 Oct 1, 2022
b8ff6d3
hacktoberfest-2022
manishsinghkuswaha Oct 1, 2022
9eec63a
Merge pull request #54 from manishsinghkuswaha/main
ajitkumar1264 Oct 1, 2022
3e8128a
Merge pull request #53 from Alia6922/main
ajitkumar1264 Oct 1, 2022
ae9cf25
Merge pull request #52 from dhirenkokal/main
ajitkumar1264 Oct 1, 2022
e8ba72f
Merge pull request #51 from Bhumi54321/main
ajitkumar1264 Oct 1, 2022
163db93
Merge pull request #50 from Suvoji01/main
ajitkumar1264 Oct 1, 2022
b3f4547
Merge pull request #48 from shubhamsingla807/main
ajitkumar1264 Oct 1, 2022
aacdaa2
Merge pull request #46 from shwetacharde/main
ajitkumar1264 Oct 1, 2022
4515b2f
Merge pull request #45 from anurag-compile/main
ajitkumar1264 Oct 1, 2022
90ca757
Create sortingUsingsort.java
palaknaugriya Oct 1, 2022
1eeca59
Merge pull request #43 from hilmyrasyiq/hacktoberfest-2022
ajitkumar1264 Oct 1, 2022
0bf6eb3
Merge pull request #42 from Saurav-Sutaria/main
ajitkumar1264 Oct 1, 2022
d9a8718
Merge pull request #41 from MeetVaishnav23/patch-3
ajitkumar1264 Oct 1, 2022
902cd25
Merge pull request #40 from MeetVaishnav23/patch-2
ajitkumar1264 Oct 1, 2022
6491961
Merge pull request #39 from MeetVaishnav23/patch-1
ajitkumar1264 Oct 1, 2022
49b3d29
Merge pull request #38 from Sparsh225/updatedalgo
ajitkumar1264 Oct 1, 2022
ca389f9
Merge pull request #55 from palaknaugriya/main
ajitkumar1264 Oct 1, 2022
166911f
Merge pull request #37 from itssubhamroy23/main
ajitkumar1264 Oct 1, 2022
cccb786
Merge pull request #35 from dharmanshu1921/main
ajitkumar1264 Oct 1, 2022
ee573bb
Date_and_time
dhirenkokal Oct 1, 2022
668300a
Determinant_of_Matrix
dhirenkokal Oct 1, 2022
3a45dc5
Create FibonacciSeries.java
vmeet95 Oct 1, 2022
90979ea
Merge pull request #57 from vmeet95/patch-1
ajitkumar1264 Oct 1, 2022
cb834a8
Merge pull request #56 from dhirenkokal/main
ajitkumar1264 Oct 1, 2022
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
29 changes: 27 additions & 2 deletions BubbleSort.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
public class BubbleSortExample {
//worst case of this code is O(n2).
static void bubbleSort(int[] arr) {
int n = arr.length;
int temp = 0;
Expand All @@ -13,8 +14,32 @@ static void bubbleSort(int[] arr) {

}
}


}
}
// An optimized version of Bubble Sort
//worst case of this code is O(n).
static void optimizedbubbleSort(int arr[], int n)
{
int i, j, temp;
boolean swapped;
for (i = 0; i < n - 1; i++)
{
swapped = false;
for (j = 0; j < n - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
swapped = true;
}
}
if (swapped == false)
break;
}
}
public static void main(String[] args) {
int arr[] ={3,60,35,2,45,320,5};

Expand All @@ -32,4 +57,4 @@ public static void main(String[] args) {
}

}
}
}
55 changes: 55 additions & 0 deletions CountingSortAlgo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Counting sort in Java programming

//import file
import java.util.Arrays;

class CountingSort {
void countSort(int array[], int size) {
int[] output = new int[size + 1];

// For Finding the largest element of the array
int max = array[0];
for (int i = 1; i < size; i++) {
if (array[i] > max)
max = array[i];
}
int[] count = new int[max + 1];

// Initialize count array with all zeros
for (int i = 0; i < max; ++i) {
count[i] = 0;
}

// Store the count of each element
for (int i = 0; i < size; i++) {
count[array[i]]++;
}

// Store the cummulative count of each array
for (int i = 1; i <= max; i++) {
count[i] += count[i - 1];
}

// Find the index of each element of the original array in count array, and
// place the elements in output array
for (int i = size - 1; i >= 0; i--) {
output[count[array[i]] - 1] = array[i];
count[array[i]]--;
}

// Copy the sorted elements into original array
for (int i = 0; i < size; i++) {
array[i] = output[i];
}
}

// Driver code for the above code
public static void main(String args[]) {
int[] data = { 4, 2, 2, 8, 3, 3, 1 };
int size = data.length;
CountingSort cs = new CountingSort();
cs.countSort(data, size);
System.out.println("Sorted Array in Ascending Order: ");
System.out.println(Arrays.toString(data));
}
}
32 changes: 32 additions & 0 deletions Date_and_time.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Java program to convert 24 hour
// time format to 12 hour format

// Importing specific date class libraries
import java.util.Date;
import java.text.SimpleDateFormat;

public class GFG {

// Main driver method
public static void main(String[] args)
{
// Getting the current current time
Date date = new Date();


System.out.println("Current Time is : " + date);

// set format in 12 hours
SimpleDateFormat formatTime = new SimpleDateFormat("hh.mm aa");
// hh = hours in 12hr format
// mm = minutes
// aa = am/pm

String time = formatTime.format(
date); // changing the format of 'date'

// display time as per format
System.out.println(
"Current Time in AM/PM Format is : " + time);
}
}
94 changes: 94 additions & 0 deletions Determinant_of_Matrix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Java program to find Determinant of a matrix
class GFG {

// Dimension of input square matrix
static final int N = 4;

// Function to get determinant of matrix
static int determinantOfMatrix(int mat[][], int n)
{
int num1, num2, det = 1, index,
total = 1; // Initialize result

// temporary array for storing row
int[] temp = new int[n + 1];

// loop for traversing the diagonal elements
for (int i = 0; i < n; i++) {
index = i; // initialize the index

// finding the index which has non zero value
while (mat[index][i] == 0 && index < n) {
index++;
}
if (index == n) // if there is non zero element
{
// the determinant of matrix as zero
continue;
}
if (index != i) {
// loop for swaping the diagonal element row
// and index row
for (int j = 0; j < n; j++) {
swap(mat, index, j, i, j);
}
// determinant sign changes when we shift
// rows go through determinant properties
det = (int)(det * Math.pow(-1, index - i));
}

// storing the values of diagonal row elements
for (int j = 0; j < n; j++) {
temp[j] = mat[i][j];
}

// traversing every row below the diagonal
// element
for (int j = i + 1; j < n; j++) {
num1 = temp[i]; // value of diagonal element
num2 = mat[j]
[i]; // value of next row element

// traversing every column of row
// and multiplying to every row
for (int k = 0; k < n; k++) {
// multiplying to make the diagonal
// element and next row element equal
mat[j][k] = (num1 * mat[j][k])
- (num2 * temp[k]);
}
total = total * num1; // Det(kA)=kDet(A);
}
}

// multiplying the diagonal elements to get
// determinant
for (int i = 0; i < n; i++) {
det = det * mat[i][i];
}
return (det / total); // Det(kA)/k=Det(A);
}

static int[][] swap(int[][] arr, int i1, int j1, int i2,
int j2)
{
int temp = arr[i1][j1];
arr[i1][j1] = arr[i2][j2];
arr[i2][j2] = temp;
return arr;
}

// Driver code
public static void main(String[] args)
{
int mat[][] = { { 1, 0, 2, -1 },
{ 3, 0, 0, 5 },
{ 2, 1, 4, -3 },
{ 1, 0, 5, 0 } };

// Function call
System.out.printf(
"Determinant of the matrix is : %d",
determinantOfMatrix(mat, N));
}
}
26 changes: 26 additions & 0 deletions Electricitybill.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class ElectricityBillExample1
{
// main() method start
public static void main(String args[])
{
// declare and initialize variable units
int units = 380;
// variable to calculate electricity bill to pay
double billToPay = 0;
// check whether units are less than 100
if(units < 100)
{
billToPay = units * 1.20;
}
// check whether the units are less than 300
else if(units < 300){
billToPay = 100 * 1.20 + (units - 100) * 2;
}
// check whether the units are greater than 300
else if(units > 300)
{
billToPay = 100 * 1.20 + 200 * 2 + (units - 300) * 3;
}
System.out.println("The electricity bill for " +units+ " is : " + billToPay);
}
}
31 changes: 31 additions & 0 deletions FactorialProgram.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.Scanner;

class Abc
{
public int f=1,i=0;

public void fact(int n)
{
for(i=1; i<=n; i++)
{
f = f*i;
}

System.out.println(n + " Factorial is : " + f);
}
}

class factorial
{
public static void main(String arr[])
{
Scanner m = new Scanner(System.in);

System.out.print("Enter Elemnt TO find Factorial : ");
int n = m.nextInt();

Abc a1 = new Abc();
a1.fact(n);

}
}
15 changes: 15 additions & 0 deletions FibonacciSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Fibonacci{
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;
}

}}
29 changes: 29 additions & 0 deletions GCD.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Java program to find Greatest Common Divisor or GCD of
* two numbers using Euclid’s method.*/
import java.util.*;
public class GCD{

public static void main(String args[]){

//Enter two number whose GCD needs to be calculated.
Scanner sc = new Scanner(System.in);
System.out.println("Please enter first number to find GCD");
int num1 = sc.nextInt();
System.out.println("Please enter second number to find GCD");
int num2 = sc.nextInt();

System.out.println("GCD of two numbers " + num1 +" and "
+ num2 +" is :" + GCD(num1,num2));


}
private static int GCD(int num1, int num2) {
//base case
if(num2 == 0){
return num1;
}
return GCD(num2, num1%num2);
}

}
Loading