From 9ed94e2ad23a3857eaec7166b7a9feaddedb740d Mon Sep 17 00:00:00 2001 From: gamixaqua Date: Fri, 13 Oct 2017 16:22:34 +0530 Subject: [PATCH 01/31] Create inputoutput.java --- inputoutput.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 inputoutput.java diff --git a/inputoutput.java b/inputoutput.java new file mode 100644 index 0000000..4e79175 --- /dev/null +++ b/inputoutput.java @@ -0,0 +1,11 @@ +package java_io; +import java.util.Scanner;//import this package for input +public class Java_io { + public static void main(String[] args) { + //for input + Scanner variable = new Scanner(System.in); + String name=variable.nextLine();//declare a variable with datatype and taking input + System.out.println(name);//output + } + +} From 1017578a4f9de2af47a072a5504fd42eecabd90f Mon Sep 17 00:00:00 2001 From: gamixaqua Date: Fri, 13 Oct 2017 19:53:08 +0530 Subject: [PATCH 02/31] Create classobject.java --- classobject.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 classobject.java diff --git a/classobject.java b/classobject.java new file mode 100644 index 0000000..341a57f --- /dev/null +++ b/classobject.java @@ -0,0 +1,14 @@ +package classobj; +public class Class { //class declaration + public static int doublee(int x){ + return x*2; + } + + public static void main(String[] args) { + Class object = new Classobj();//declaring an object for class Class + int x=5; + int y = object.doublee(x);//calling a method of class Class + System.out.println(y); + } + +} From 1194e4f4214345eda46f12bd9e93482840eb1ac8 Mon Sep 17 00:00:00 2001 From: gamixaqua Date: Fri, 13 Oct 2017 19:54:15 +0530 Subject: [PATCH 03/31] Update classobject.java --- classobject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classobject.java b/classobject.java index 341a57f..bba2233 100644 --- a/classobject.java +++ b/classobject.java @@ -5,7 +5,7 @@ public static int doublee(int x){ } public static void main(String[] args) { - Class object = new Classobj();//declaring an object for class Class + Class object = new Class();//declaring an object for class Class int x=5; int y = object.doublee(x);//calling a method of class Class System.out.println(y); From a77d04679bb97b3a27aa65f4b353a394abdd2fef Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Sun, 15 Oct 2017 16:53:27 +0530 Subject: [PATCH 04/31] Update and rename inputoutput.java to input_output/inputoutput.java --- input_output/inputoutput.java | 36 +++++++++++++++++++++++++++++++++++ inputoutput.java | 11 ----------- 2 files changed, 36 insertions(+), 11 deletions(-) create mode 100644 input_output/inputoutput.java delete mode 100644 inputoutput.java diff --git a/input_output/inputoutput.java b/input_output/inputoutput.java new file mode 100644 index 0000000..e76282b --- /dev/null +++ b/input_output/inputoutput.java @@ -0,0 +1,36 @@ +import java.util.Scanner; +//import this package for input + +public class java_io_II +{ + public static void main(String[] args) { + //for input + Scanner Sc = new Scanner(System.in); + + // variable "input_x" takes the input for data type x + + // for integer inputs + int input_i = Sc.nextInt(); + System.out.println("Input = " + input_i); + + // for Long_Integer inputs + long input_l = Sc.nextLong(); + System.out.println("Input = " + input_l); + + // for float inputs + float input_f = Sc.nextFloat(); + System.out.println("Input = " + input_f); + + // for double_float inputs + double input_d = Sc.nextDouble(); + System.out.println("Input = " + input_d); + + // for String inputs WORD by WORD + String input_St = Sc.next(); + System.out.println("Input = " + input_St); + + // for String inputs Entire Line + input_St = Sc.nextLine(); + System.out.println("Input = " + input_St); + } +} diff --git a/inputoutput.java b/inputoutput.java deleted file mode 100644 index 4e79175..0000000 --- a/inputoutput.java +++ /dev/null @@ -1,11 +0,0 @@ -package java_io; -import java.util.Scanner;//import this package for input -public class Java_io { - public static void main(String[] args) { - //for input - Scanner variable = new Scanner(System.in); - String name=variable.nextLine();//declare a variable with datatype and taking input - System.out.println(name);//output - } - -} From f1a930f6e32049c21333051e8f8b0190b7568d02 Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Sun, 15 Oct 2017 16:54:07 +0530 Subject: [PATCH 05/31] Rename inputoutput.java to java_io_II.java --- input_output/{inputoutput.java => java_io_II.java} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename input_output/{inputoutput.java => java_io_II.java} (100%) diff --git a/input_output/inputoutput.java b/input_output/java_io_II.java similarity index 100% rename from input_output/inputoutput.java rename to input_output/java_io_II.java From 50d216c76bb881da0a1cacba6750e3c58bbb2cf6 Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Sun, 15 Oct 2017 16:58:08 +0530 Subject: [PATCH 06/31] Create java_io_I.java --- input_output/java_io_I.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 input_output/java_io_I.java diff --git a/input_output/java_io_I.java b/input_output/java_io_I.java new file mode 100644 index 0000000..44a0bcd --- /dev/null +++ b/input_output/java_io_I.java @@ -0,0 +1,6 @@ +import java.io.InputStreamReader; +import java.io.BufferedReader; +import java.io.IOException; +public class java_io_I +{ +} From b8adc98f4f6a199c2a644ebfeafc0a96a577247d Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Sun, 15 Oct 2017 17:04:39 +0530 Subject: [PATCH 07/31] Update java_io_I.java --- input_output/java_io_I.java | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/input_output/java_io_I.java b/input_output/java_io_I.java index 44a0bcd..1fc6da6 100644 --- a/input_output/java_io_I.java +++ b/input_output/java_io_I.java @@ -3,4 +3,44 @@ import java.io.IOException; public class java_io_I { + public static void main(String[] args)throws IOException + // throw the Exception class object for input-output exceptions ie. IOException + { + InputStreamReader Isr = new InputStreamReader (System.in); + BufferedReader Br = new BufferedReader (Isr); + + // all inputs are taken as Strings + // also the entire line is taken as input + // Now just parse the String into whichever data type required. + + String input; + int input_i; + long input_l; + float input_f; + double input_d; + char input_c; + + input = Br.readLine(); // Taking input as a String + System.out.println(input); // String Input + + input = Br.readLine(); // Taking input as a String + input_i = Integer.parseInt (input); // parsing input + System.out.println(input_i); + + input = Br.readLine(); // Taking input as a String + input_l = Long.parseLong (input); // parsing input + System.out.println(input_l); + + input = Br.readLine(); // Taking input as a String + input_f = Float.parseFloat (input); // parsing input + System.out.println(input_f); + + input = Br.readLine(); // Taking input as a String + input_d = Double.parseDouble (input); // parsing input + System.out.println(input_d); + + input_c = (char) Br.read(); // Taking input as a character + Br = new BufferedReader (Isr); // flush the junk characters (of newline or carriage return) from the input buffer + System.out.println(input_c); + } } From 0dc6d34f767e765d76a775f31cc42c3ddbf1fa74 Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Sun, 15 Oct 2017 17:09:55 +0530 Subject: [PATCH 08/31] Update and rename classobject.java to class_and_objects/class_object.java --- class_and_objects/class_object.java | 27 +++++++++++++++++++++++++++ classobject.java | 14 -------------- 2 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 class_and_objects/class_object.java delete mode 100644 classobject.java diff --git a/class_and_objects/class_object.java b/class_and_objects/class_object.java new file mode 100644 index 0000000..6223c6a --- /dev/null +++ b/class_and_objects/class_object.java @@ -0,0 +1,27 @@ +public class class_object +{ + //class declaration + public int square(int x) + { + return x*2; + } + public double square_rt (int x) + { + return Math.sqrt (x); + } + public static void main(String[] args) + { + // using the command line arguements as input + int x = Integer.parseInt (args[0]); + + Class object = new Class(); // declaring an object for class Class + + int y = object.square (x); // calling a method of class Class + double z = object.square_rt (x); // calling a method of class Class + + System.out.println("Input number = " + x); + System.out.println("Square of number = " + y); + System.out.println("Square root of number = " + z); + } + +} diff --git a/classobject.java b/classobject.java deleted file mode 100644 index bba2233..0000000 --- a/classobject.java +++ /dev/null @@ -1,14 +0,0 @@ -package classobj; -public class Class { //class declaration - public static int doublee(int x){ - return x*2; - } - - public static void main(String[] args) { - Class object = new Class();//declaring an object for class Class - int x=5; - int y = object.doublee(x);//calling a method of class Class - System.out.println(y); - } - -} From e60b025ba41450630a9f10a0e64d4462b61cd7ad Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Wed, 18 Oct 2017 22:38:20 +0530 Subject: [PATCH 09/31] Create selection_sort.java --- sorting/selection_sort.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 sorting/selection_sort.java diff --git a/sorting/selection_sort.java b/sorting/selection_sort.java new file mode 100644 index 0000000..d03f507 --- /dev/null +++ b/sorting/selection_sort.java @@ -0,0 +1,4 @@ +import java.util.Scanner; +public class selection_sort +{ +} From 475e033d68b7e08c61fd98f3d9896796ec844bdd Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Wed, 18 Oct 2017 23:02:31 +0530 Subject: [PATCH 10/31] selection sorting --- sorting/selection_sort.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/sorting/selection_sort.java b/sorting/selection_sort.java index d03f507..5c804d1 100644 --- a/sorting/selection_sort.java +++ b/sorting/selection_sort.java @@ -1,4 +1,36 @@ import java.util.Scanner; public class selection_sort { + public static void sorting(int[] arr) + { + // Selection sorting in Ascending Order + int i, j, p, temp; + for (i = 0; i < arr.length; ++i) { + p = i; + for (j = i + 1; j < arr.length; ++j) { + p = arr[j] < arr[p] ? j : p; + } + temp = arr[i]; + arr[i] = arr[p]; + arr[p] = temp; + } + } + public static void main(String[] args) + { + int i, size; + Scanner Sc = new Scanner (System.in); + System.out.print("Enter size of array :- "); + size = Sc.nextInt(); + int[] arr = new int[size]; + System.out.print("Enter elements :- "); + for (i = 0; i < size; ++i) { + arr[i] = Sc.nextInt(); + } + sorting(arr); + System.out.println("Sorted array :-"); + for (i = 0; i < size; ++i) { + System.out.print(arr[i] + " "); + } + System.out.println(); + } } From 5b64042b04373cb1e91d1130ac8845319733121c Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Wed, 18 Oct 2017 23:05:33 +0530 Subject: [PATCH 11/31] Create bubble_sort.java --- sorting/bubble_sort.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 sorting/bubble_sort.java diff --git a/sorting/bubble_sort.java b/sorting/bubble_sort.java new file mode 100644 index 0000000..9c37cf9 --- /dev/null +++ b/sorting/bubble_sort.java @@ -0,0 +1 @@ +import From 3ca95024c0c7ebd72bea25e2a55a3e171c8ccede Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Wed, 18 Oct 2017 23:09:35 +0530 Subject: [PATCH 12/31] bubble_sort --- sorting/bubble_sort.java | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/sorting/bubble_sort.java b/sorting/bubble_sort.java index 9c37cf9..aa9c65c 100644 --- a/sorting/bubble_sort.java +++ b/sorting/bubble_sort.java @@ -1 +1,36 @@ -import +import java.util.Scanner; +public class bubble_sort +{ + public static void sorting(int[] arr) + { + // Bubble sorting in Ascending Order + int i, j, temp; + for (i = 0; i < arr.length; ++i) { + for (j = 0; j < arr.length - i - 1; ++j) { + if (arr[j] > arr[j + 1]) { + temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + } + } + } + } + public static void main(String[] args) + { + int i, size; + Scanner Sc = new Scanner (System.in); + System.out.print("Enter size of array :- "); + size = Sc.nextInt(); + int[] arr = new int[size]; + System.out.print("Enter elements :- "); + for (i = 0; i < size; ++i) { + arr[i] = Sc.nextInt(); + } + sorting(arr); + System.out.println("Sorted array :-"); + for (i = 0; i < size; ++i) { + System.out.print(arr[i] + " "); + } + System.out.println(); + } +} From 8724ca261317139058d5c6e5a1d78547c84fca66 Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Wed, 18 Oct 2017 23:20:41 +0530 Subject: [PATCH 13/31] insertion_sorting --- sorting/insertion_sort.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 sorting/insertion_sort.java diff --git a/sorting/insertion_sort.java b/sorting/insertion_sort.java new file mode 100644 index 0000000..cae71d3 --- /dev/null +++ b/sorting/insertion_sort.java @@ -0,0 +1,34 @@ +import java.util.Scanner; +public class selection_sort +{ + public static void sorting(int[] arr) + { + // Selection sorting in Ascending Order + int i, j, key; + for (i = 1; i < arr.length; ++i) { + key = arr[i]; + for (j = i - 1; j >= 0 && arr[j] > key; --j) { + arr[j + 1] = arr[j]; + } + arr[j + 1] = key; + } + } + public static void main(String[] args) + { + int i, size; + Scanner Sc = new Scanner (System.in); + System.out.print("Enter size of array :- "); + size = Sc.nextInt(); + int[] arr = new int[size]; + System.out.print("Enter elements :- "); + for (i = 0; i < size; ++i) { + arr[i] = Sc.nextInt(); + } + sorting(arr); + System.out.println("Sorted array :-"); + for (i = 0; i < size; ++i) { + System.out.print(arr[i] + " "); + } + System.out.println(); + } +} From 2771ae3f0732abfd789e54a5797066b8ad231b81 Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Wed, 18 Oct 2017 23:23:19 +0530 Subject: [PATCH 14/31] Create merge_sort.java --- sorting/merge_sort.java | 1 + 1 file changed, 1 insertion(+) create mode 100644 sorting/merge_sort.java diff --git a/sorting/merge_sort.java b/sorting/merge_sort.java new file mode 100644 index 0000000..9a8e219 --- /dev/null +++ b/sorting/merge_sort.java @@ -0,0 +1 @@ +import java.util.Scanner; From 11e8cd41082482d2df5fb9fbf0e78ab6ca65304a Mon Sep 17 00:00:00 2001 From: gamixaqua Date: Wed, 18 Oct 2017 23:43:19 +0530 Subject: [PATCH 15/31] Create Selection_Statements.java --- Selection_Statements.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Selection_Statements.java diff --git a/Selection_Statements.java b/Selection_Statements.java new file mode 100644 index 0000000..d8c71c1 --- /dev/null +++ b/Selection_Statements.java @@ -0,0 +1,36 @@ + +package selectionstatements; + + +public class Selection_Statements { + public static String IfElse(int x){ + if(x%2==0){ + return "even"; + } + else{ + return "odd"; + } + } + public static String Switch(int x){ + switch(x){ + case 1 : + return "it's one"; + case 2 : + return "it's two"; + case 3 : + return "it's three"; + default: + return "out of my knowledge"; + } + } + + + public static void main(String[] args) { + Selection_Statements obj = new Selection_Statements(); + String y = obj.IfElse(123); + System.out.println("The number is "+ y); + String x=obj.Switch(2); + System.out.println("switch statements result is :"+ x); + } + +} From ec41045528dc3c79233df4fba1c52b9ab13a95b9 Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Wed, 18 Oct 2017 23:55:12 +0530 Subject: [PATCH 16/31] merge_sort --- sorting/merge_sort.java | 73 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/sorting/merge_sort.java b/sorting/merge_sort.java index 9a8e219..b43a10f 100644 --- a/sorting/merge_sort.java +++ b/sorting/merge_sort.java @@ -1 +1,74 @@ import java.util.Scanner; +public class merge_sort +{ + /** + * Merge sorting + * a divide and conquer based sorting method. + * You divide the array into two parts from the middle. + * Now sort both the parts and merge them later on. + * You keep dividing till you get arrays of size = 1, + * because an array of size = 1 is always sorted. + */ + public static void sorting(int[] arr, int i, int j) + { + if (i < j) { + int m = (i + j) / 2; + sorting (arr, i, m); + sorting (arr, m + 1, j); + merging (arr, i, m, j); + } + } + public static void merging (int[] arr, int i, int m, int j) + { + int[] l = new int[m - i + 1]; + int[] r = new int[j - m]; + int x, y, a, b; + for (x = 0, a = i; a <= m; ++x, ++a) { + l[x] = arr[a]; + } + for (y = 0; a <= j; ++y, ++a) { + r[y] = arr[a]; + } + for (a = 0, b = 0; a < x && b < y; ++i) { + if (l[a] <= r[b]) { + arr[i] = l[a]; + ++a; + } else { + arr[i] = r[b]; + ++b; + } + } + for ( ; a < x; ++a, ++i) { + arr[i] = l[a]; + } + for ( ; b < y; ++b, ++i) { + arr[i] = r[b]; + } + } + public static void display(int[] arr) + { + int i; + for (i = 0; i < arr.length; ++i) { + System.out.print(arr[i] + " "); + } + System.out.println(); + } + public static void main(String[] args) + { + int i, size; + Scanner Sc = new Scanner (System.in); + System.out.print("Enter size of array :- "); + size = Sc.nextInt(); + int[] arr = new int[size]; + System.out.print("Enter elements :- "); + for (i = 0; i < size; ++i) { + arr[i] = Sc.nextInt(); + } + sorting(arr); + System.out.println("Sorted array :-"); + for (i = 0; i < size; ++i) { + System.out.print(arr[i] + " "); + } + System.out.println(); + } +} From 2422d4426aee3f56b3c1caba3a596e7af26c52d1 Mon Sep 17 00:00:00 2001 From: gamixaqua Date: Thu, 19 Oct 2017 00:44:40 +0530 Subject: [PATCH 17/31] Create loops.java --- loops.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 loops.java diff --git a/loops.java b/loops.java new file mode 100644 index 0000000..aa04e89 --- /dev/null +++ b/loops.java @@ -0,0 +1,26 @@ +public class loops { + public static void number(int x){ //using while loop + while(x<10){ + x++; + System.out.println(x); + } + } + public static void even(int z){ + do{ + System.out.println( z ); + z=z+2; + }while(z<=10); + } + public static void table(int y){//using for loop + for(int i=1;i<=10;i++){ + System.out.println(i*y); + } + } +public static void main(String[] args){ + System.out.println("Number from 1 to 10"); + loops.number(0); + System.out.println("Even Numbers between 0 to 10"); + loops.even(0); + System.out.println("Table of 8"); + loops.table(8); +} From df6e7b5003875db4e06e4e80a5a2f2092960e13d Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Thu, 19 Oct 2017 15:53:11 +0530 Subject: [PATCH 18/31] updated the file --- Loops.java | 35 +++++++++++++++++++++++++++++++++++ loops.java | 26 -------------------------- 2 files changed, 35 insertions(+), 26 deletions(-) create mode 100644 Loops.java delete mode 100644 loops.java diff --git a/Loops.java b/Loops.java new file mode 100644 index 0000000..3a263d6 --- /dev/null +++ b/Loops.java @@ -0,0 +1,35 @@ +public class Loops +{ + public static void number(int x) + { + //using while loop + while (x < 10) { + ++x; + System.out.println(x); + } + } + public static void even(int z) + { + do { + System.out.println (z); + z += 2; + } while (z <= 10); + } + public static void table(int y) + { + //using for loop + int i; + for (i = 1; i <= 10; ++i) { + System.out.println(i*y); + } + } + public static void main(String[] args) + { + System.out.println("Number from 1 to 10"); + number(0); + System.out.println("Even Numbers between 0 to 10"); + even(0); + System.out.println("Table of 8"); + table(8); + } +} diff --git a/loops.java b/loops.java deleted file mode 100644 index aa04e89..0000000 --- a/loops.java +++ /dev/null @@ -1,26 +0,0 @@ -public class loops { - public static void number(int x){ //using while loop - while(x<10){ - x++; - System.out.println(x); - } - } - public static void even(int z){ - do{ - System.out.println( z ); - z=z+2; - }while(z<=10); - } - public static void table(int y){//using for loop - for(int i=1;i<=10;i++){ - System.out.println(i*y); - } - } -public static void main(String[] args){ - System.out.println("Number from 1 to 10"); - loops.number(0); - System.out.println("Even Numbers between 0 to 10"); - loops.even(0); - System.out.println("Table of 8"); - loops.table(8); -} From 9281296346925eb36d9bcd143e1dc61f2297b4bd Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Tue, 24 Oct 2017 19:09:13 +0530 Subject: [PATCH 19/31] corrected the readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 72a8910..d7818d5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # Java-Guide-for-Beginners - This will be an Open Guide for all beginners in Python ! You can read and learn simple Java codes here , and whats more interesting is that you can even Contribute !!! +## This will be an Open Guide for all beginners in JAVA! +You can read and learn simple Java codes here , and whats more interesting is that you can even Contribute !!! From 4037491836941d10211ba4ab2d113220279cc709 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Tue, 24 Oct 2017 19:14:50 +0530 Subject: [PATCH 20/31] rectification --- sorting/merge_sort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sorting/merge_sort.java b/sorting/merge_sort.java index b43a10f..d339fe7 100644 --- a/sorting/merge_sort.java +++ b/sorting/merge_sort.java @@ -64,7 +64,7 @@ public static void main(String[] args) for (i = 0; i < size; ++i) { arr[i] = Sc.nextInt(); } - sorting(arr); + sorting(arr, 0, size - 1); System.out.println("Sorted array :-"); for (i = 0; i < size; ++i) { System.out.print(arr[i] + " "); From 07e81f39ce970493309280b70f22c96c31877830 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Tue, 24 Oct 2017 19:59:48 +0530 Subject: [PATCH 21/31] quick_sorting --- sorting/quick_sort.java | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 sorting/quick_sort.java diff --git a/sorting/quick_sort.java b/sorting/quick_sort.java new file mode 100644 index 0000000..0c3e7fb --- /dev/null +++ b/sorting/quick_sort.java @@ -0,0 +1,65 @@ +import java.util.Scanner; +public class quick_sort +{ + /** + * Quick sorting + * a divide-based sorting method. + * You take an element (preferably the last) -- PIVOT, + * now divide the array into two parts, + * front part has elements less than or equal to PIVOT + * rear part has elements grater than PIVOT + * now use quick sorting on both the parts. + */ + public static int partition(int arr[], int low, int high) + { + int pivot = arr[high]; + int i, j; // index of smaller element + for (i = low - 1, j = low; j < high; ++j) { + if (arr[j] <= pivot) { + ++i; + int temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + } + int temp = arr[i+1]; + arr[i+1] = arr[high]; + arr[high] = temp; + + return i + 1; + } + public static void sorting (int[] arr, int i, int j) + { + if (i < j) { + int p = partition (arr, i, j); + sorting (arr, i, p - 1); + sorting (arr, p + 1, j); + } + } + public static void display(int[] arr) + { + int i; + for (i = 0; i < arr.length; ++i) { + System.out.print(arr[i] + " "); + } + System.out.println(); + } + public static void main(String[] args) + { + int i, size; + Scanner Sc = new Scanner (System.in); + System.out.print("Enter size of array :- "); + size = Sc.nextInt(); + int[] arr = new int[size]; + System.out.print("Enter elements :- "); + for (i = 0; i < size; ++i) { + arr[i] = Sc.nextInt(); + } + sorting(arr, 0, size - 1); + System.out.println("Sorted array :-"); + for (i = 0; i < size; ++i) { + System.out.print(arr[i] + " "); + } + System.out.println(); + } +} From b01d737d4c0e0fae58b0d565d667c7349a6d83a8 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Tue, 24 Oct 2017 23:15:03 +0530 Subject: [PATCH 22/31] generic_sorting --- sorting/sorting | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 sorting/sorting diff --git a/sorting/sorting b/sorting/sorting new file mode 100644 index 0000000..131086e --- /dev/null +++ b/sorting/sorting @@ -0,0 +1,72 @@ +import java.util.Scanner; +import java.util.Comparator; +import java.util.Arrays; +public class sorting +{ + /** + * This makes use of the Generic Sorting method provided in JAVA + * This sorts the given array of any type. + * The comparator class object specifies how the sorting is to be done. + */ + public static void main(String[] args) throws Exception + { + int i, size; + Scanner Sc = new Scanner(System.in); + size = Sc.nextInt(); + req_data[] arr = new req_data[size]; + for (i = 0; i < size; ++i) { + arr[i] = new req_data(); + arr[i].set_name (Sc.next()); + arr[i].set_val (Sc.nextInt()); + } + Arrays.sort (arr, 0, size, new myComp()); + for (i = 0; i < size; ++i) { + System.out.println(arr[i].get_name() + " " + arr[i].get_val()); + } + } +} +class req_data +{ + private String name; + private int val; + public void set_name (String name) + { + this.name = name; + } + public void set_val (int val) + { + this.val = val; + } + public String get_name() + { + return name; + } + public int get_val() + { + return val; + } +} +class myComp implements Comparator +{ + /** + * Sorting is done by val (increasing), + * then by name (decreasing) + */ + public int compare(req_data obj0, req_data obj1) + { + if (obj0.get_val() > obj1.get_val()) { + return 1; + } else if (obj0.get_val() == obj1.get_val()) { + int c = obj0.get_name().compareTo (obj1.get_name()); + if (c < 0) { + return 1; + } else if (c == 0) { + return 0; + } else { + return -1; + } + } else { + return -1; + } + } +} From 9727b091b9a468eacfa1a240ef5392af208622d2 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Wed, 25 Oct 2017 12:33:39 +0530 Subject: [PATCH 23/31] binary_exponentiation --- mathematics/binary_expo_I.java | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 mathematics/binary_expo_I.java diff --git a/mathematics/binary_expo_I.java b/mathematics/binary_expo_I.java new file mode 100644 index 0000000..07284aa --- /dev/null +++ b/mathematics/binary_expo_I.java @@ -0,0 +1,67 @@ +import java.util.Scanner; +/** + * @author jackdaw14-9 + * @version 1.0 dated 10/08/2017 + */ + /** + * Binary Exponentiation + * for powering two numbers. + * also useful for calculating - (a^b) % c + */ +public class binary_expo_I +{ + public static int b_expo(int a, int b) + { + /* + * iterative solution + */ + int res; + for (res = 1; b > 0; a *= a, b >>= 1) { + if ((b&1) == 1) { + res *= a; + } + } + return res; + /* + * recursive solution + if (b == 0) { + return 1; + } + if (b == 1) { + return a; + } + if ((b & 1) == 1) { + return a * b_expo(a*a, b >> 1); + } else { + return b_expo (a*a, b >> 1); + } + */ + } + public static long b_expo(long a, long b, long c) + { + /* + * iterative solution + */ + long res; + for (res = 1l; b > 0; a *=a, b >>= 1) { + if ((b&1) == 1) { + res = ((res%c) * (a%c)) % c; + } + } + return res; + /* + * recursive solution + if (b == 0) { + return 1; + } + if (b == 1) { + return a; + } + if ((b & 1) == 1) { + return ((a%c) * (b_expo(a*a, b >> 1)%c))%c; + } else { + return b_expo (a*a, b >> 1)%c; + } + */ + } +} From 42d8778a427d1f8e0823ffe23b0364bf895e7957 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Wed, 25 Oct 2017 12:34:37 +0530 Subject: [PATCH 24/31] binary_exponentiation_multiplication --- mathematics/binary_expo_II.java | 76 +++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 mathematics/binary_expo_II.java diff --git a/mathematics/binary_expo_II.java b/mathematics/binary_expo_II.java new file mode 100644 index 0000000..eb89a34 --- /dev/null +++ b/mathematics/binary_expo_II.java @@ -0,0 +1,76 @@ +/** +* Binary Exponentiation for MULTIPLICATION +* Method to find a*b in O(log(b)) time complexity. +* Also useful in finding solution to (a*b)%c, where a, b, c are WAY OVER THE INTEGER LIMITS. +* +* +* Wondering how it works ?! +* Well, it's quite simple. +* RULE 1 :- a*b = (a+a) * (b/2) +* RULE 2 :- IF b is ODD THEN -- a*b = a + (a * (b - 1)) :: where (b - 1) will be EVEN. NOW apply RULE 1 +* Repeat RULE 1, 2 till b = 0 OR b = 1, because a * 0 = 0 AND a * 1 = a +* +* As far as the MOD is concerned, +* RULE 3 :- (a+b) % c = ((a%c) + (b%c)) % c +* Now, apply RULE 1 or 2, whichever is required. +*/ +public class binary_expo_II +{ + public static int b_expo(int a, int b) + { + /* + * iterative solution + */ + int res; + for (res = 0; b > 0; a += a, b >>= 1) { + if ((b&1) == 1) { + res += a; + } + } + return res; + + /* + * recursive solution + if (b == 0) { + return 0; + } + if (b == 1) { + return a; + } + if ((b & 1) == 1) { + return a + b_expo(a+a, b >> 1); + } else { + return b_expo (a+a, b >> 1); + } + */ + } + + public static long b_expo(long a, long b, long c) + { + /* + * iterative solution + */ + long res; + for (res = 0l; b > 0; a += a, b >>= 1) { + if ((b&1) == 1) { + res = ((res%c) + (a%c)) % c; + } + } + return res; + + /* + * recursive solution + if (b == 0) { + return 0; + } + if (b == 1) { + return a; + } + if ((b & 1) == 1) { + return ((a%c) + (b_expo(a+a, b >> 1)%c))%c; + } else { + return b_expo (a+a, b >> 1)%c; + } + */ + } +} From f32bb007e07fe3aed283ed88bc9e99f2cbae20e0 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Wed, 25 Oct 2017 12:35:21 +0530 Subject: [PATCH 25/31] Euclidean_GCD_method --- mathematics/Euclidean_GCD.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mathematics/Euclidean_GCD.java diff --git a/mathematics/Euclidean_GCD.java b/mathematics/Euclidean_GCD.java new file mode 100644 index 0000000..55afec6 --- /dev/null +++ b/mathematics/Euclidean_GCD.java @@ -0,0 +1,20 @@ +/** +* Euclidean algorithm for finding the GCD of two numbers. +* Time complexity is O(log(max(A, B))) +*/ +public class Euclidean_GCD +{ + public static int gcd(int a, int b) + { + /** + * Iterative solution + */ + int res = 1; + for ( ; a % b != 0; ) { + res = a % b; + a = b; + b = res; + } + return res; + } +} From 40fc2e57c9f30929445750f40b4c396a208cfbd3 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Wed, 25 Oct 2017 12:37:59 +0530 Subject: [PATCH 26/31] counting_set_bits_in_a_number --- mathematics/set_bits.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 mathematics/set_bits.java diff --git a/mathematics/set_bits.java b/mathematics/set_bits.java new file mode 100644 index 0000000..d7c6bf4 --- /dev/null +++ b/mathematics/set_bits.java @@ -0,0 +1,15 @@ +/** + * Brian Kernighan's algorithm for finding number of set bits in a number. + * Time Complexity -- O(logn) + */ +public class set_bits +{ + public static int function(int a) + { + int count; + for (count = 0; a > 0; ++count) { + a = a & (a - 1); + } + return count; + } +} From f6766a40b5d60ce8dd97e3766bb99da23ac932a4 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Wed, 25 Oct 2017 12:38:32 +0530 Subject: [PATCH 27/31] remainder_of_division --- mathematics/remainder.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 mathematics/remainder.java diff --git a/mathematics/remainder.java b/mathematics/remainder.java new file mode 100644 index 0000000..46ae41a --- /dev/null +++ b/mathematics/remainder.java @@ -0,0 +1,27 @@ +/** +* JAVA program to find remainder of a/b +* NOTE -- NUMBER OF DIGITS IN a <= 100000 +*/ +import java.util.Scanner; +public class remainder +{ + public static int function(String a, int b) + { + int res, i, j; + j = a.length(); + for (res = 0, i = 0; i < j; ++i) { + res = (res * 10 + (a.charAt(i) - 48)) % b; + } + return res; + } + public static void main(String[] args) + { + String a; + int b, res; + Scanner Sc = new Scanner(System.in); + a = Sc.next(); + b = Sc.nextInt(); + res = function (a, b); + System.out.println(res); + } +} From d45df85652e1f6482a3c975d1429a5a9f1619e7d Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Thu, 26 Oct 2017 10:44:14 +0530 Subject: [PATCH 28/31] infix to postfix --- data_structures/infix_to_postfix.java | 106 ++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 data_structures/infix_to_postfix.java diff --git a/data_structures/infix_to_postfix.java b/data_structures/infix_to_postfix.java new file mode 100644 index 0000000..6a1b59f --- /dev/null +++ b/data_structures/infix_to_postfix.java @@ -0,0 +1,106 @@ +import java.util.Scanner; +import java.util.StringTokenizer; + +/** + * Program to convert infix expression to postfix. + * Input format :- there have to be spaces in between numbers and mathematical signs + * + - * / % ^ ( ) are considered. + * example of input :- a * b - c / d * ( e - f ) ^ g + h + * example of output :- a b * c d / e f - g ^ * - h + + */ +public class infix_to_postfix +{ + public static int precedence(String sign) + { + switch (sign) { + case "+": + case "-": + return 0; + case "*": + case "/": + return 1; + case "%": + return 2; + case "^": + return 3; + case "(": + case ")": + return 4; + default: + return 5; + } + } + + public static void main(String[] args) + { + String St, i; + Scanner Sc = new Scanner (System.in); + Stack stack = new Stack(); + St = Sc.nextLine(); + StringTokenizer obj = new StringTokenizer(St); + for (St = obj.nextToken(); obj.hasMoreTokens(); St = obj.nextToken()) { + if (St.equals("(")) { + stack.push (St); + continue; + } + if (St.equals(")")) { + for (i = stack.top(); !stack.is_empty(); stack.pop(), i = stack.top()) { + if (i.equals("(")) { + stack.pop(); + break; + } else { + System.out.print(i + " "); + } + } + continue; + } + if (St.equals("+") || St.equals("-") || St.equals("*") || St.equals("/") || St.equals("%") || St.equals("^")) { + for ( ; !stack.is_empty(); ) { + i = stack.top(); + if (i.equals("(")) { + break; + } + if (precedence (i) >= precedence (St)) { + System.out.print(i + " "); + stack.pop(); + } else { + break; + } + } + stack.push (St); + } else { + System.out.print(St + " "); + } + } + System.out.print(St + " "); + for ( ; !stack.is_empty(); stack.pop()) { + System.out.print(stack.top() + " "); + } + } +} +class Stack { + private String[] arr; + private int size; + public Stack() + { + size = 0; + arr = new String[10000]; + } + public String top() + { + return arr[size - 1]; + } + public void pop() + { + --size; + } + public void push (String val) + { + arr[size] = val; + ++size; + } + public boolean is_empty() + { + return size == 0; + } +} From 2d28ee66a7678b410321b086de04f2d78886a556 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Thu, 26 Oct 2017 10:46:09 +0530 Subject: [PATCH 29/31] basic map data structure --- data_structures/maps_I.java | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 data_structures/maps_I.java diff --git a/data_structures/maps_I.java b/data_structures/maps_I.java new file mode 100644 index 0000000..58b1ac5 --- /dev/null +++ b/data_structures/maps_I.java @@ -0,0 +1,63 @@ +import java.util.HashMap; +import java.util.Map; +import java.util.Scanner; + +public class maps_I +{ + public static void main(String[] args) + { + Map my_map = new HashMap(); + Scanner Sc = new Scanner(System.in); + int choice; + String St; int key; + do { + choice = Sc.nextInt(); + switch (choice) { + case 1: + // check + key = Sc.nextInt(); + System.out.println(my_map.containsKey(key)); + St = Sc.next(); + System.out.println(my_map.containsValue(St)); + break; + case 2: + // insert + // if key-value pair exists, + // then it replaces the existing pair with the new pair ! + key = Sc.nextInt(); + St = Sc.next(); + my_map.put(key, St); + break; + case 3: + // get value + key = Sc.nextInt(); + System.out.println(my_map.get(key)); + break; + case 4: + // size + System.out.println(my_map.size()); + break; + case 5: + // clear the map + my_map.clear(); + break; + case 6: + // remove an element + key = Sc.nextInt(); + System.out.println("Removed :- " + my_map.get(key)); + my_map.remove(key); + break; + case 7: + System.out.println(my_map); + System.out.println(my_map.keySet()); + System.out.println(my_map.entrySet()); + break; + case 10: + System.exit(0); + break; + default: + System.out.println("Try Again"); + } + } while (true); + } +} From dad77def7472155e31b5db1235ea6525a9333f48 Mon Sep 17 00:00:00 2001 From: Shubhojeet Das Date: Thu, 26 Oct 2017 10:48:22 +0530 Subject: [PATCH 30/31] example in Map --- data_structures/maps_ex_1.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 data_structures/maps_ex_1.java diff --git a/data_structures/maps_ex_1.java b/data_structures/maps_ex_1.java new file mode 100644 index 0000000..c901a11 --- /dev/null +++ b/data_structures/maps_ex_1.java @@ -0,0 +1,34 @@ +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Scanner; +/** + * java.util.HashMap is unordered. + * This class makes no guarantees as to the order of the map, + * in particular, it does not guarantee that the order will remain constant over time. + * + * java.util.LinkedHashMap uses insertion-order. + * This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. + * This linked list defines the iteration ordering, + * which is normally the order in which keys were inserted into the map (insertion-order). + * + * java.util.TreeMap, a SortedMap, uses either natural or custom ordering of the keys. + * The map is sorted according to the natural ordering of its keys, + * or by a Comparator provided at map creation time, depending on which constructor is used. + */ +public class maps_ex_1 +{ + public static void main(String[] args) + { + String St; Integer key; + int t; + Scanner Sc = new Scanner(System.in); + Map my_map = new LinkedHashMap(); + for (t = Sc.nextInt(); t > 0; --t) { + St = Sc.next(); + key = my_map.get(St); + my_map.put(St, (key == null) ? 1 : key + 1); + } + System.out.println(my_map.size()); + System.out.println(my_map); + } +} From 4dc7827820de3b1eef90ba286ed95e9356533113 Mon Sep 17 00:00:00 2001 From: Chinmoy Das Date: Wed, 17 Oct 2018 00:03:48 +0530 Subject: [PATCH 31/31] Create pom.xml --- spring_test_1/pom.xml | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 spring_test_1/pom.xml diff --git a/spring_test_1/pom.xml b/spring_test_1/pom.xml new file mode 100644 index 0000000..27883d5 --- /dev/null +++ b/spring_test_1/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + + com.example + test-one + 0.0.1-SNAPSHOT + jar + + test-one + First Sample of SpringBoot + + + org.springframework.boot + spring-boot-starter-parent + 2.0.2.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + org.springframework.boot + spring-boot-starter-web + + + + mysql + mysql-connector-java + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + +