From 37838f6237aaa79b882f1476634495af093893e6 Mon Sep 17 00:00:00 2001 From: The-TJ <32796932+The-TJ@users.noreply.github.com> Date: Fri, 17 Nov 2017 12:32:45 +0000 Subject: [PATCH 1/8] Create HextoDec.java Program that converts Hexadecimal numbers to decimal. --- Conversions/HexToOct.java | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Conversions/HexToOct.java diff --git a/Conversions/HexToOct.java b/Conversions/HexToOct.java new file mode 100644 index 00000000..7d5579ff --- /dev/null +++ b/Conversions/HexToOct.java @@ -0,0 +1,49 @@ +/* Java Program - Convert Hexadecimal to Octal +Author - Tanmay Joshi*/ + +import java.util.Scanner; + +public class HexToOct +{ + public static int hex2decimal(String s) + { + String str = "0123456789ABCDEF"; + s = s.toUpperCase(); + int val = 0; + for (int i = 0; i < s.length(); i++) + { + char a = s.charAt(i); + int n = str.indexOf(a); + val = 16*val + n; + } + return val; + } + public static void main(String args[]) + { + String hexadecnum; + int decnum, i=1, j; + int octnum[] = new int[100]; + Scanner scan = new Scanner(System.in); + + System.out.print("Enter Hexadecimal Number : "); + hexadecnum = scan.nextLine(); + + // first convert hexadecimal to decimal + + decnum = hex2decimal(hexadecnum); + + // convert decimal to octal + + while(decnum != 0) + { + octnum[i++] = decnum%8; + decnum = decnum/8; + } + + System.out.print("Equivalent Octal Number is :\n"); + for(j=i-1; j>0; j--) + { + System.out.print(octnum[j]); + } + } +} From 61aaa5925fcf65c310cd2ece8af39ebe79d1cea7 Mon Sep 17 00:00:00 2001 From: The-TJ <32796932+The-TJ@users.noreply.github.com> Date: Wed, 22 Nov 2017 17:38:51 +0000 Subject: [PATCH 2/8] Update HexToOct.java --- Conversions/HexToOct.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Conversions/HexToOct.java b/Conversions/HexToOct.java index 7d5579ff..275fe84e 100644 --- a/Conversions/HexToOct.java +++ b/Conversions/HexToOct.java @@ -4,7 +4,8 @@ Author - Tanmay Joshi*/ import java.util.Scanner; public class HexToOct -{ +{ + //Function that takes the Hexadecimal number as input and returns the decimal form. public static int hex2decimal(String s) { String str = "0123456789ABCDEF"; @@ -17,7 +18,8 @@ public class HexToOct val = 16*val + n; } return val; - } + } + // Main function that gets the hex input from user and converts it into octal. public static void main(String args[]) { String hexadecnum; @@ -39,7 +41,7 @@ public class HexToOct octnum[i++] = decnum%8; decnum = decnum/8; } - + //Print the octal form of the number. System.out.print("Equivalent Octal Number is :\n"); for(j=i-1; j>0; j--) { From 402c4e8738ea86d633a96dad3eee183da05439da Mon Sep 17 00:00:00 2001 From: The-TJ <32796932+The-TJ@users.noreply.github.com> Date: Wed, 22 Nov 2017 17:43:48 +0000 Subject: [PATCH 3/8] Update HexToOct.java --- Conversions/HexToOct.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Conversions/HexToOct.java b/Conversions/HexToOct.java index 275fe84e..47b8d7c7 100644 --- a/Conversions/HexToOct.java +++ b/Conversions/HexToOct.java @@ -5,10 +5,11 @@ import java.util.Scanner; public class HexToOct { - //Function that takes the Hexadecimal number as input and returns the decimal form. + /*Function that takes the Hexadecimal number as input and returns the decimal form. + The input is recieved as a string and the return type is int*/ public static int hex2decimal(String s) { - String str = "0123456789ABCDEF"; + String str = "0123456789ABCDEF"; s = s.toUpperCase(); int val = 0; for (int i = 0; i < s.length(); i++) @@ -19,20 +20,20 @@ public class HexToOct } return val; } - // Main function that gets the hex input from user and converts it into octal. + // Main method that gets the hex input from user and converts it into octal. public static void main(String args[]) { String hexadecnum; int decnum, i=1, j; - int octnum[] = new int[100]; + int octnum[] = new int[100]; //Array to store the octal from of the hex number. Scanner scan = new Scanner(System.in); System.out.print("Enter Hexadecimal Number : "); - hexadecnum = scan.nextLine(); + hexadecnum = scan.nextLine(); // first convert hexadecimal to decimal - decnum = hex2decimal(hexadecnum); + decnum = hex2decimal(hexadecnum); //Pass the string to the hex2decimal function and get the decimal form in variable decnum // convert decimal to octal From 27839d2f63bee5cca1f5dd888ed37fa30e44d0a8 Mon Sep 17 00:00:00 2001 From: The-TJ <32796932+The-TJ@users.noreply.github.com> Date: Sun, 26 Nov 2017 20:36:39 +0000 Subject: [PATCH 4/8] Update HexToOct.java --- Conversions/HexToOct.java | 60 ++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/Conversions/HexToOct.java b/Conversions/HexToOct.java index 47b8d7c7..d00b0a90 100644 --- a/Conversions/HexToOct.java +++ b/Conversions/HexToOct.java @@ -1,12 +1,20 @@ -/* Java Program - Convert Hexadecimal to Octal -Author - Tanmay Joshi*/ - +/** + + * Converts any Hexadecimal Number to Octal + + * + + * @author Tanmay Joshi + + * + + */ import java.util.Scanner; public class HexToOct { - /*Function that takes the Hexadecimal number as input and returns the decimal form. - The input is recieved as a string and the return type is int*/ + /** + + * This method converts a Hexadecimal number to + + * a decimal number + + * + + * @param The Hexadecimal Number + + * @return The Decimal number + + */ public static int hex2decimal(String s) { String str = "0123456789ABCDEF"; @@ -20,12 +28,34 @@ public class HexToOct } return val; } + + /** + + * This method converts a Decimal number to + + * a octal number + + * + + * @param The Decimal Number + + * @return The Octal number + + */ + public static int decimal2octal(int q) + { + int now; + int i=1; + int octnum=0; + while(q>0) + { + now=q%8; + octnum=(now*(int)(Math.pow(10,i)))+octnum; + q/=8; + i++; + } + octnum/=10; + return octnum; + } // Main method that gets the hex input from user and converts it into octal. public static void main(String args[]) { String hexadecnum; - int decnum, i=1, j; - int octnum[] = new int[100]; //Array to store the octal from of the hex number. + int decnum,octalnum; Scanner scan = new Scanner(System.in); System.out.print("Enter Hexadecimal Number : "); @@ -34,19 +64,11 @@ public class HexToOct // first convert hexadecimal to decimal decnum = hex2decimal(hexadecnum); //Pass the string to the hex2decimal function and get the decimal form in variable decnum - + // convert decimal to octal + octalnum=decimal2octal(decnum); + System.out.println("Number in octal: "+octalnum); + - while(decnum != 0) - { - octnum[i++] = decnum%8; - decnum = decnum/8; - } - //Print the octal form of the number. - System.out.print("Equivalent Octal Number is :\n"); - for(j=i-1; j>0; j--) - { - System.out.print(octnum[j]); - } } } From b26b8f4acf454132f10c7d3ea3229f3d77c19fa4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 2 Dec 2017 23:03:15 +0900 Subject: [PATCH 5/8] Updated DecimalToHexaDecimal.java --- Conversions/DecimalToHexaDecimal.java | 55 +++++++++++++-------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/Conversions/DecimalToHexaDecimal.java b/Conversions/DecimalToHexaDecimal.java index 3072dec0..251d10c3 100644 --- a/Conversions/DecimalToHexaDecimal.java +++ b/Conversions/DecimalToHexaDecimal.java @@ -1,33 +1,30 @@ -import java.lang.StringBuilder; -import java.util.Scanner; -class Test { - private static final int sizeOfIntInHalfBytes = 8; - private static final int numberOfBitsInAHalfByte = 4; - private static final int halfByte = 0x0F; - private static final char[] hexDigits = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' - }; +class DecimalToHexaDecimal { + private static final int sizeOfIntInHalfBytes = 8; + private static final int numberOfBitsInAHalfByte = 4; + private static final int halfByte = 0x0F; + private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', + 'F' }; - public static String decToHex(int dec) { - StringBuilder hexBuilder = new StringBuilder(sizeOfIntInHalfBytes); - hexBuilder.setLength(sizeOfIntInHalfBytes); - for (int i = sizeOfIntInHalfBytes - 1; i >= 0; --i) - { - int j = dec & halfByte; - hexBuilder.setCharAt(i, hexDigits[j]); - dec >>= numberOfBitsInAHalfByte; - } - return hexBuilder.toString(); - } + // Returns the hex value of the dec entered in the parameter. + public static String decToHex(int dec) { + StringBuilder hexBuilder = new StringBuilder(sizeOfIntInHalfBytes); + hexBuilder.setLength(sizeOfIntInHalfBytes); + for (int i = sizeOfIntInHalfBytes - 1; i >= 0; --i) { + int j = dec & halfByte; + hexBuilder.setCharAt(i, hexDigits[j]); + dec >>= numberOfBitsInAHalfByte; + } + return hexBuilder.toString().toLowerCase(); + } - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - System.out.println("Write your Number to convert into HexaDecimal: ") - int dec = 305445566; - String hex = Integer.toHexString(dec); - String hex = decToHex(dec); - System.out.println(hex); - } + // Test above function. + public static void main(String[] args) { + System.out.println("Test..."); + int dec = 305445566; + String libraryDecToHex = Integer.toHexString(dec); + String decToHex = decToHex(dec); + System.out.println("Result from the library : " + libraryDecToHex); + System.out.println("Result decToHex method : " + decToHex); + } } \ No newline at end of file From 8ceea5609d83dfd3318276b25b35125014d094bd Mon Sep 17 00:00:00 2001 From: JeonSeongBae Date: Wed, 6 Dec 2017 13:17:56 +0900 Subject: [PATCH 6/8] verticies to vertices --- Data Structures/Graphs/MatrixGraphs.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Data Structures/Graphs/MatrixGraphs.java b/Data Structures/Graphs/MatrixGraphs.java index 424e69b8..f064c012 100644 --- a/Data Structures/Graphs/MatrixGraphs.java +++ b/Data Structures/Graphs/MatrixGraphs.java @@ -80,7 +80,7 @@ class AdjacencyMatrixGraph { /** * This method adds an edge to the graph between two specified - * verticies + * vertices * * @param from the data of the vertex the edge is from * @param to the data of the vertex the edge is going to @@ -101,7 +101,7 @@ class AdjacencyMatrixGraph { /** * this method removes an edge from the graph between two specified - * verticies + * vertices * * @param from the data of the vertex the edge is from * @param to the data of the vertex the edge is going to From 62fdf0d44e801b32b38963843f39245c2570d490 Mon Sep 17 00:00:00 2001 From: NISHITA97 Date: Fri, 8 Dec 2017 02:33:47 +0530 Subject: [PATCH 7/8] Kadane's Algorithm added --- Dynamic Programming/KadaneAlgorithm.java | 55 ++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Dynamic Programming/KadaneAlgorithm.java diff --git a/Dynamic Programming/KadaneAlgorithm.java b/Dynamic Programming/KadaneAlgorithm.java new file mode 100644 index 00000000..e82de100 --- /dev/null +++ b/Dynamic Programming/KadaneAlgorithm.java @@ -0,0 +1,55 @@ +import java.util.Scanner; + +/** + * Program to implement Kadane’s Algorithm to + * calculate maximum contiguous subarray sum of an array + * Time Complexity: O(n) + * + * @author Nishita Aggarwal + * + */ + +public class KadaneAlgorithm { + + /** + * This method implements Kadane's Algorithm + * + * @param arr The input array + * @return The maximum contiguous subarray sum of the array + * + */ + static int largestContiguousSum(int arr[]){ + int i,len=arr.length,cursum=0,maxsum=Integer.MIN_VALUE; + if(len==0) //empty array + return 0; + for(i=0;imaxsum){ + maxsum=cursum; + } + if(cursum<=0){ + cursum=0; + } + } + return maxsum; + } + + /** + * Main method + * + * @param args Command line arguments + */ + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int n,arr[],i; + n=sc.nextInt(); + arr=new int[n]; + for(i=0;i Date: Fri, 8 Dec 2017 02:36:20 +0530 Subject: [PATCH 8/8] Update KadaneAlgorithm.java --- Dynamic Programming/KadaneAlgorithm.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dynamic Programming/KadaneAlgorithm.java b/Dynamic Programming/KadaneAlgorithm.java index e82de100..56d0ec6f 100644 --- a/Dynamic Programming/KadaneAlgorithm.java +++ b/Dynamic Programming/KadaneAlgorithm.java @@ -14,10 +14,10 @@ public class KadaneAlgorithm { /** * This method implements Kadane's Algorithm * - * @param arr The input array + * @param arr The input array * @return The maximum contiguous subarray sum of the array - * - */ + * + */ static int largestContiguousSum(int arr[]){ int i,len=arr.length,cursum=0,maxsum=Integer.MIN_VALUE; if(len==0) //empty array