addition of characters in string TC= O(n^2); Get link Facebook X Pinterest Email Other Apps - June 15, 2024 class characteradd{ public static void main(String[] args) { String str="tony"; for(char i='a';i<'z';i++){ str+=i; } System.out.println(str); }} Get link Facebook X Pinterest Email Other Apps Comments
Convert first letter to capital letter in java - June 15, 2024 import javax . xml . transform . stax . StAXSource ; class firstupper { public static String capital ( String str ){ StringBuilder strbuild = new StringBuilder (); char ch = Character . toUpperCase ( str . charAt ( 0 )); strbuild . append ( ch ); for ( int i = 1 ; i < str . length (); i ++){ if ( str . charAt ( i ) == ' ' && i < str . length () - 1 ){ strbuild . append ( str . charAt ( i )); i ++; strbuild . append ( Character . toUpperCase ( str . charAt ( i ))); } else { strbuild . appen... Read more
Stair case traversal search - June 13, 2024 import java . util .* ; class stairs { public static void main ( String [] args ) { int m [][] = {{ 10 , 20 , 30 , 40 }, { 15 , 25 , 34 , 45 }, { 27 , 29 , 37 , 48 }, { 32 , 33 , 39 , 50 }}; int start = m [ 0 ][ m . length - 1 ], key = 37 ; int i = 0 , j = m [ 0 ]. length - 1 , z = 1 ; while ( start != key ){ // if(key==start){ // System.out.print("key found at position "+i+" "+j); // z--; ... Read more
Palindrome of string my logic - June 13, 2024 import java . util .* ; class strings { public static void main ( String [] args ) { String str = "racpar" ; String palendrome ; int count = 0 , i = 0 ; int start = 0 , end = str . length () - 1 ; while ( i < end ){ if ( str . charAt ( i ) == str . charAt ( end )){ count ++; end --; i ++; } else { break ; } } if ( count == str . length () / 2 ){ System . out . println ( "Stri... Read more
Comments
Post a Comment