From 19d311e993de7648e869b942382ae6f8a23e79c4 Mon Sep 17 00:00:00 2001 From: Manmeet Singh Date: Wed, 4 Oct 2017 00:22:54 +0530 Subject: [PATCH 1/7] Create Palindromic Prime --- Misc/PalindromicPrime.java | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Misc/PalindromicPrime.java diff --git a/Misc/PalindromicPrime.java b/Misc/PalindromicPrime.java new file mode 100644 index 00000000..86646720 --- /dev/null +++ b/Misc/PalindromicPrime.java @@ -0,0 +1,41 @@ +import java.util.Scanner; +public class PalindromePrime { + + public static void main(String[] args) { // Main funtion + Scanner in = new Scanner(System.in); + System.out.println("Enter the quantity of First Palindromic Primes you want"); + int n = in.nextInt(); // Input of how mant first pallindromic prime we want + funtioning(n); // calling funtion - functioning + } + + public static boolean prime(int num) { // checking if number is prime or not + for (int divisor = 2; divisor <= num / 2; divisor++) { + if (num % divisor == 0) { + return false; // false if not prime + } + } + return true; // True if prime + } + + public static int reverse(int n){ // Returns the reverse of the number + int reverse = 0; + while(n!=0){ + reverse = reverse * 10; + reverse = reverse + n%10; + n = n/10; + } + return reverse; + } + + public static void funtioning(int y){ + int count =0; + int num = 2; + while(count < y){ + if(prime(num) && num == reverse(num)){ // number is prime and it's reverse is same + count++; // counts check when to terminate while loop + System.out.print(num + "\n"); // Print the Palindromic Prime + } + num++; // inrease iterator value by one + } + } +}; From 2ae49305e99886d16d6b0fbd2278b598f6265f2d Mon Sep 17 00:00:00 2001 From: Rachana040 Date: Sat, 23 Dec 2017 22:44:06 +0530 Subject: [PATCH 2/7] Updated Matrix.java, added Transpose of a Matrix --- Data Structures/Matrix/Matrix.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Data Structures/Matrix/Matrix.java b/Data Structures/Matrix/Matrix.java index edbdcdbf..a26dfe97 100644 --- a/Data Structures/Matrix/Matrix.java +++ b/Data Structures/Matrix/Matrix.java @@ -221,4 +221,20 @@ public class Matrix { return str; } + + /** + * Returns transposed matrix of this matrix. + * + * @return transposed Matrix. + */ + public Matrix transpose() { + + int[][] newData = new int[this.data[0].length][this.data.length]; + + for (int i = 0; i < this.getColumns(); ++i) + for(int j = 0; j < this.getRows(); ++j) + newData[i][j] = this.data[j][i]; + + return new Matrix(newData); + } } From b2fc59899a23b404644de983028947b542e80608 Mon Sep 17 00:00:00 2001 From: Rachana040 Date: Sun, 24 Dec 2017 12:03:12 +0530 Subject: [PATCH 3/7] Added PowerOfTwoOrNot to Others --- Others/PowerOfTwoOrNot.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Others/PowerOfTwoOrNot.java diff --git a/Others/PowerOfTwoOrNot.java b/Others/PowerOfTwoOrNot.java new file mode 100644 index 00000000..36facfed --- /dev/null +++ b/Others/PowerOfTwoOrNot.java @@ -0,0 +1,33 @@ +import java.util.Scanner; + +/** +*A utility to check if a given number is power of two or not. +*For example 8,16 etc. +*/ +public class PowerOfTwoOrNot { + + public static void main (String[] args) { + + Scanner sc = new Scanner(System.in); + System.out.println("Enter the number"); + int num = sc.nextInt(); + boolean isPowerOfTwo = checkIfPowerOfTwoOrNot(num); + if (isPowerOfTwo) { + System.out.println("Number is a power of two"); + } else { + System.out.println("Number is not a power of two"); + } + } + + +/** +* Checks whether given number is power of two or not. +* +* @param number +* @return boolean +*/ +public static boolean checkIfPowerOfTwoOrNot(int number) { + return number != 0 && ((number & (number-1)) == 0); + } + +} From 652d227982a0b1b8298038a4ee9d3ac1cc62516e Mon Sep 17 00:00:00 2001 From: Prasoon Date: Wed, 24 Jan 2018 21:27:30 +0530 Subject: [PATCH 4/7] Close the scanner --- Others/CountChar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Others/CountChar.java b/Others/CountChar.java index 1c8dcfea..25f23d61 100644 --- a/Others/CountChar.java +++ b/Others/CountChar.java @@ -14,7 +14,7 @@ public class CountChar { Scanner input = new Scanner(System.in); System.out.print("Enter your text: "); String str = input.nextLine(); - + input.close(); System.out.println("There are " + CountCharacters(str) + " characters."); } From 206b9aa75f38ea9767d25e57239b43f4fe4de8e7 Mon Sep 17 00:00:00 2001 From: Prasoon Date: Wed, 24 Jan 2018 21:28:38 +0530 Subject: [PATCH 5/7] Change access specifier to private --- Others/CountChar.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Others/CountChar.java b/Others/CountChar.java index 25f23d61..6504aabb 100644 --- a/Others/CountChar.java +++ b/Others/CountChar.java @@ -24,7 +24,7 @@ public class CountChar { * @return int: Number of characters in the passed string * */ - public static int CountCharacters(String str) { + private static int CountCharacters(String str) { int count = 0; From 2638ce639608aa84bb087ea42c37905c63fed548 Mon Sep 17 00:00:00 2001 From: Prasoon Date: Wed, 31 Jan 2018 15:59:28 +0530 Subject: [PATCH 6/7] Set method to private --- Others/countwords.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Others/countwords.java b/Others/countwords.java index 30806e13..a72ef9c9 100644 --- a/Others/countwords.java +++ b/Others/countwords.java @@ -18,7 +18,7 @@ import java.util.Scanner; input.close(); } - public static int wordCount(String s){ + private static int wordCount(String s){ if(s.isEmpty() || s == null) return -1; return s.trim().split("[\\s]+").length; } From f1200c06cedf3f5cb581ee5fb87af3a17b068a98 Mon Sep 17 00:00:00 2001 From: Prasoon Date: Wed, 31 Jan 2018 16:00:04 +0530 Subject: [PATCH 7/7] Fix a logical error --- Others/countwords.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Others/countwords.java b/Others/countwords.java index a72ef9c9..a93aa1a3 100644 --- a/Others/countwords.java +++ b/Others/countwords.java @@ -19,7 +19,7 @@ import java.util.Scanner; } private static int wordCount(String s){ - if(s.isEmpty() || s == null) return -1; + if(s.isEmpty() || s == null) return 0; return s.trim().split("[\\s]+").length; }