Posts

Pascal Triangle

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 import java.util.Scanner ; public class PasclasTriangleProgram { public static void main ( String args []) { Scanner in = new Scanner ( System . in ); System . out . println ( "Enter number of rows " ); int rows = in . nextInt (); for ( int i = 0 ; i < rows ; i ++) { int number = 1 ; System . out . format ( "%" + ( rows - i ) * 2 + "s" , "" ); for ( int j = 0 ; j <= i ; j ++) { System . out . format ( "%4d" , number ); number = number * ( i - j ) / ( j + 1 ); } System . out . println (); } } }

Data Structure : Quick Sort

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 64 65 66 public class QuickSort { private int array []; private int length ; public void sort ( int [] inputArr ) { if ( inputArr == null || inputArr . length == 0 ) { return ; } this . array = inputArr ; length = inputArr . length ; quickSort ( 0 , length - 1 ); } private void quickSort ( int lowerIndex , int higherIndex ) { int i = lowerIndex ; int j = higherIndex ; // calculate pivot number, I am taking pivot as middle index number int pivot = array [ lowerIndex +( higherIndex - lowerIndex )/ 2 ]; // Divide into two arrays while ( i <= j ) { /** * In each itera...

Data Structure : Insertion Sort

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 public class InsertionSort { public static void main ( String a []){ int [] arr1 = { 10 , 34 , 2 , 56 , 7 , 67 , 88 , 42 }; int [] arr2 = doInsertionSort ( arr1 ); for ( int i: arr2 ){ System . out . print ( i ); System . out . print ( ", " ); } } public static int [] doInsertionSort ( int [] input ){ int temp ; for ( int i = 1 ; i < input . length ; i ++) { for ( int j = i ; j > 0 ; j --){ if ( input [ j ] < input [ j - 1 ]){ temp = input [ j ]; input [ j ] = input [ j - 1 ]; input [ j - 1 ] = temp ; } } } return input ; } }

Data Structure : Select Sort

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 public class SelectionSort { public static int [] doSelectionSort ( int [] arr ){ for ( int i = 0 ; i < arr . length - 1 ; i ++) { int index = i ; for ( int j = i + 1 ; j < arr . length ; j ++) if ( arr [ j ] < arr [ index ]) index = j ; int smallerNumber = arr [ index ]; arr [ index ] = arr [ i ]; arr [ i ] = smallerNumber ; } return arr ; } public static void main ( String a []){ int [] arr1 = { 10 , 34 , 2 , 56 , 7 , 67 , 88 , 42 }; int [] arr2 = doSelectionSort ( arr1 ); for ( int i: arr2 ){ System . out . print ( i ); System . out . print ( ", " ); } } }

Oracle database connection

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 /* ORACLE DataBase Connection */ import java.sql.* ; class OracleConnection { public static void main ( String [] rk ) { try { System . out . println ( "connecting..." ); //DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); Class . forName ( "oracle.jdbc.driver.OracleDriver" ); System . out . println ( "Loading Loaded Successfully...." ); Connection conn = DriverManager . getConnection ( "jdbc:oracle:thin:@192.168.100.10:1521/Stud10g" , "kirpal" , "kirpal" ); System . out . println ( "Connection done Successfully......" ); Statement stmt 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22...

My-Sql database connection

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 import java.sql.* ; public class Mysql { public static void main ( String [] rk ) { Connection con = null ; Statement stmt = null ; ResultSet rs = null ; try { Class . forName ( "com.mysql.jdbc.Driver" ); con = DriverManager . getConnection ( "jdbc:mysql://localhost/mytables" , "root" , "magnet" ); stmt = con . createStatement (); rs = stmt . executeQuery ( "select * from contacts" ); while ( rs . next ()) { System . out . println ( rs . getString ( 1 )); } } catch ( Exception e ) { System . out . println ( "Error : " + e ); } } } /* Copy your MySql Connector .jar fi...

MS-SQL database connection code and Steps

step1:Create your instance using the sqlexpre.exe file select the required settings during the setup. step2. after creating the instance open the sql server conf manager step3. enable the tcp/ip and do the required settings for the port no (1433) and local host ip address (127.0.0.1) step4.start the created instance. step5.open the cmd prompt step6. type c:\>sqlcmd step7. c:\>sp_databasesc:\>go (Note: this command will show u the default databases) step8. c:\>create database databasename c:\>go step9.c:\>exit ster10.Add the requires version of .jar file means driver into the libraries folder in your project. step11. open the services window in netbeans step12.RClick on the database option select the new connection option. step13.load the appropriate driver in the basic settings tab. (your .jar file of the driver) step14.give the required values in the shows fields. 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 ...