Skip to main content

Posts

Showing posts from February, 2019

Comaparison between ParallelSort and Sort in JAVA

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 import java.util.ArrayList ; import java.util.Arrays ; import java.util.Random ; public class sortvsparllelsort { public static void main ( String [] args ) { Random random = new Random (); System . out . println ( "Comparison between Sort and Parallel Sort" ); ArrayList < Integer > arraylist = new ArrayList <>(); for ( long i = 1 ; i < 10000000L ; i ++) { arraylist . add ( random . nextInt ( 900 )); } System . out . println ( "ArrayList has been initialised" ); Integer a []= new Integer [ arraylist . size ()]; Integer b []= new Integer [ arraylist . size ()]; System . out . println ( "Both normal arrays are initialised" ); a = arraylist . toArray ( a ); b = Arrays . copyOf ( a , a . length

JAVA program to Calculate Factorial using Function Interface (involve lambdas )

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 import java.util.Scanner ; import java.util.function.Function ; public class fact { public static void main ( String [] args ) { Function < Integer , String > fact =( n )-> { String res = "Factorial of " + n + " is=" ; double a = 1 ; for ( int i = 1 ; i <= n ; i ++) a *= i ; return res + a ; }; Scanner in = new Scanner ( System . in ); System . out . print ( "Enter the number :" ); int num = in . nextInt (); System . out . println ( fact . apply ( num )); } }

C program to find whether two Strings are cyclic Anagram or not

Example 1.first String: abcd  second string:dabc  output:They are cyclic anagram 2.  first String: abcd  second string:dcab output:They are not  cyclic anagram CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 # include # include int main() { char s[ 100 ], b[ 100 ], temp; int n, len, i; printf( "Enter the String \n " ); scanf( "%s" , s); printf( " \n Entered String=%s" , s); printf( " \n Enter String to be matched->" ); scanf( "%s" , b); printf( " \n Entered String to be matched->%s" , b); len = strlen(s); if (len != strlen(b)) { printf( " \n they are not cyclic anagram \n " ); getchar(); return 0 ; }