File tree Expand file tree Collapse file tree 5 files changed +94
-4
lines changed Expand file tree Collapse file tree 5 files changed +94
-4
lines changed Original file line number Diff line number Diff line change @@ -221,4 +221,20 @@ public String toString() {
221
221
222
222
return str ;
223
223
}
224
+
225
+ /**
226
+ * Returns transposed matrix of this matrix.
227
+ *
228
+ * @return transposed Matrix.
229
+ */
230
+ public Matrix transpose () {
231
+
232
+ int [][] newData = new int [this .data [0 ].length ][this .data .length ];
233
+
234
+ for (int i = 0 ; i < this .getColumns (); ++i )
235
+ for (int j = 0 ; j < this .getRows (); ++j )
236
+ newData [i ][j ] = this .data [j ][i ];
237
+
238
+ return new Matrix (newData );
239
+ }
224
240
}
Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+ public class PalindromePrime {
3
+
4
+ public static void main (String [] args ) { // Main funtion
5
+ Scanner in = new Scanner (System .in );
6
+ System .out .println ("Enter the quantity of First Palindromic Primes you want" );
7
+ int n = in .nextInt (); // Input of how mant first pallindromic prime we want
8
+ funtioning (n ); // calling funtion - functioning
9
+ }
10
+
11
+ public static boolean prime (int num ) { // checking if number is prime or not
12
+ for (int divisor = 2 ; divisor <= num / 2 ; divisor ++) {
13
+ if (num % divisor == 0 ) {
14
+ return false ; // false if not prime
15
+ }
16
+ }
17
+ return true ; // True if prime
18
+ }
19
+
20
+ public static int reverse (int n ){ // Returns the reverse of the number
21
+ int reverse = 0 ;
22
+ while (n !=0 ){
23
+ reverse = reverse * 10 ;
24
+ reverse = reverse + n %10 ;
25
+ n = n /10 ;
26
+ }
27
+ return reverse ;
28
+ }
29
+
30
+ public static void funtioning (int y ){
31
+ int count =0 ;
32
+ int num = 2 ;
33
+ while (count < y ){
34
+ if (prime (num ) && num == reverse (num )){ // number is prime and it's reverse is same
35
+ count ++; // counts check when to terminate while loop
36
+ System .out .print (num + "\n " ); // Print the Palindromic Prime
37
+ }
38
+ num ++; // inrease iterator value by one
39
+ }
40
+ }
41
+ };
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public static void main(String[] args) {
14
14
Scanner input = new Scanner (System .in );
15
15
System .out .print ("Enter your text: " );
16
16
String str = input .nextLine ();
17
-
17
+ input . close ();
18
18
System .out .println ("There are " + CountCharacters (str ) + " characters." );
19
19
}
20
20
@@ -24,7 +24,7 @@ public static void main(String[] args) {
24
24
* @return int: Number of characters in the passed string
25
25
* */
26
26
27
- public static int CountCharacters (String str ) {
27
+ private static int CountCharacters (String str ) {
28
28
29
29
int count = 0 ;
30
30
Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+
3
+ /**
4
+ *A utility to check if a given number is power of two or not.
5
+ *For example 8,16 etc.
6
+ */
7
+ public class PowerOfTwoOrNot {
8
+
9
+ public static void main (String [] args ) {
10
+
11
+ Scanner sc = new Scanner (System .in );
12
+ System .out .println ("Enter the number" );
13
+ int num = sc .nextInt ();
14
+ boolean isPowerOfTwo = checkIfPowerOfTwoOrNot (num );
15
+ if (isPowerOfTwo ) {
16
+ System .out .println ("Number is a power of two" );
17
+ } else {
18
+ System .out .println ("Number is not a power of two" );
19
+ }
20
+ }
21
+
22
+
23
+ /**
24
+ * Checks whether given number is power of two or not.
25
+ *
26
+ * @param number
27
+ * @return boolean
28
+ */
29
+ public static boolean checkIfPowerOfTwoOrNot (int number ) {
30
+ return number != 0 && ((number & (number -1 )) == 0 );
31
+ }
32
+
33
+ }
Original file line number Diff line number Diff line change @@ -18,8 +18,8 @@ public static void main(String[] args){
18
18
input .close ();
19
19
}
20
20
21
- public static int wordCount (String s ){
22
- if (s .isEmpty () || s == null ) return - 1 ;
21
+ private static int wordCount (String s ){
22
+ if (s .isEmpty () || s == null ) return 0 ;
23
23
return s .trim ().split ("[\\ s]+" ).length ;
24
24
}
25
25
You can’t perform that action at this time.
0 commit comments