Posts

Tree in java

  package T rees ; class node { int val ; node left ; node right ; public node ( int val ){     this . val = val ; } } public class NodeTree { public static void main ( String [] args ) { node a = new node ( 1 ); node b = new node ( 4 ); node c = new node ( 3 ); node d = new node ( 2 ); node e = new node ( 6 ); node f = new node ( 5 ); a . left = b ; a . right = c ; b . left = d ; b . right = e ; c . right = f ; System . out . print ( "product of all nodes : " ); System . out . print ( product ( a )); System . out . println (); System . out . print ( "product of non-zero elements of nodes : " ); System . out . print ( product2 ( a )); System . out . println (); System . out . print ( "sum of all nodes : " ); System . out . print ( sum ( a )); System . out . println (); System . out . print ( "Maximum Node in tree : " ); System . out . print ( maximum ( a )); System . out . println (); System . out . print ( ...

Exception Handling.

Try Catch -> // Arithmatic Exception p ackage E xception_ H andling ; public class try_catch {     public static void main ( String [] args ) {         int a = 10 , b = 0 , c ;         try {             c = a / b ;             System . out . println ( c );         } catch ( ArithmeticException e ){             System . out . println ( e );         }     } } // NullPointer Exception package E xception_ H andling ; public class try_catch {     public static void main ( String [] args ) {         String s = null ;         try {             System . out . println ( s . toUpperCase ());         } catch ( NullPointerException e ){             System . out . ...

dbms

Image
                                                                                                    

javascript

Image
                                                                                                                                                           

Linked List Create in java.

  package L inked L ist ; class Node {     int val ;     Node next ;     Node ( int val ){         this . val = val ;     } } public class ListNodeClass { // print function using temp node public static void print ( Node head ){ Node temp = head ; while ( temp != null ){     System . out . println ( temp . val );     temp = temp . next ; } } // print list reverse order using recursion public static void dispRevRec ( Node head ){ if ( head == null ) return ; dispRevRec ( head . next ); System . out . println ( head . val ); } // print list using recursion public static void dispRec ( Node head ){ if ( head == null ) return ; System . out . println ( head . val ); dispRec ( head . next ); } public static void main ( String [] args ) { Node a = new Node ( 10 ); Node b = new Node ( 20 ); Node c = new Node ( 30 ); Node d = new Node ( 40 ); Node e = new Node ( 50 );...

Single Linked List in java.

package L inked L ist ; class sll {     Node head ;     Node tail ;     int size ; void printSize (){     System . out . println ( "size is = " + size ); } void print (){ if ( head == null ){     System . out . println ( "List is empty" );     return ; } System . out . println ( "linked list is =>" ); Node temp = head ; while ( temp != null ){     System . out . print ( temp . val + " " );     temp = temp . next ; } System . out . println (); } void deleteAtStart (){ if ( head == null ){     System . out . println ( "list is empty" );     return ; } // only one node if ( head == tail ){     head = tail = null ; } else {     head = head . next ; }     size -- ; } void deleteAtIndex ( int ix ){     if ( ix < 0 || ix >= size ){     throw new RuntimeException ( "invalid index" );     }     if ( ix ...

substring function in java.

  package program ; import java . util .* ; public class code {     public static void main ( String [] args ) {     Scanner sc = new Scanner ( System . in );     System . out . println ( "enter srting=" );     String s = sc . nextLine ();     String t = "" ;     System . out . println ( "enter value of i=" );     int i = sc . nextInt ();     for ( int j = i ; j < s . length (); j ++ ){         t += s . charAt ( j );     }     System . out . println ( "substring is =" + t );    } } // function 2 -> package program ; import java . util .* ; public class code {     public static void main ( String [] args ) {     Scanner sc = new Scanner ( System . in );     System . out . println ( "enter srting=" );     String s = sc . nextLine ();     String t = "" ;     ...