logo

Caso di cammello a Giava

Java segue la sintassi camel-case per denominare classi, interfacce, metodi e variabili. Se il nome è combinato con due parole, la seconda parola inizierà sempre con la lettera maiuscola, come maxMarks( ), lastName, ClassTest, rimuovendo tutti gli spazi.

q3 mesi

Esistono due modi per utilizzare la custodia Camel:

  1. Cammello minuscolo dove il primo carattere della prima parola è minuscolo. Questa convenzione viene solitamente seguita durante la denominazione dei metodi e delle variabili. Esempio, firstName, lastName, actionEvent, printArray(), ecc.
  2. Il caso Upper Camel è noto anche come caso del titolo, dove il primo carattere della prima parola è in maiuscolo. Questa convenzione viene solitamente seguita durante la denominazione delle classi e delle interfacce. Ad esempio, Dipendente, Stampabile e così via.

Conversione di una corda normale in una custodia color cammello

Una stringa può essere convertita nella convenzione maiuscola o maiuscola semplicemente rimuovendo gli spazi dalla stringa.

Esempio di caso del cammello inferiore:

Ingresso: JavaTpoint è il miglior sito di tutorial per i linguaggi di programmazione.

Produzione: javaTpointIsTheBestTutorialSiteForProgrammingLanguages.

Esempio di caso del cammello superiore:

Ingresso: questo è il tutorial di Java

Produzione: Questo è il tutorial di Java

derivato parziale nel lattice

Algoritmo:

  1. Attraversa l'array di caratteri carattere per carattere fino a raggiungere la fine.
  2. La prima lettera della stringa su indice = 0 viene convertita in minuscolo (quando segue il maiuscolo cammello minuscolo) o in maiuscolo (quando segue il maiuscolo cammello superiore).
  3. Viene controllata la presenza di spazi nell'array e la lettera immediatamente successiva allo spazio viene convertita in maiuscolo.
  4. Se viene rilevato il carattere diverso dallo spazio, viene copiato nell'array risultante.

Implementiamo l'algoritmo in un programma Java.

A. Conversione di una corda in una custodia Camel inferiore

LowerCamel.java

 public class LowerCamel { // function to convert the string into lower camel case static String convertString( String s ) { // to keep track of spaces int ctr = 0 ; // variable to hold the length of the string int n = s.length( ) ; // converting the string expression to character array char ch[ ] = s.toCharArray( ) ; // keep track of indices of ch[ ] array int c = 0 ; // traversing through each character of the array for ( int i = 0; i <n; 0 1 i++ ) { the first position of array i.e., letter must be converted to lower case as we are following camel in this program if( i="=" converting using tolowercase( in-built function ch[ ]="Character.toLowerCase(" ; need remove all spaces between, check for empty if ( ' incrementing space counter by ctr++ immediately after upper + continue loop } is not encountered simply copy character else c++ size new string will reduced have been removed thus, returning with return string.valueof( ch, 0, n - ctr driver code public static void main( args[ passing name a method str="Max Marks()" system.out.println( convertstring( variable str1="Last name" str2="JavaTpoint is the best tutorial site for programming languages." < pre> <p> <strong>Output:</strong> </p> <pre> maxMarks() lastName javaTpointIsTheBestTutorialSiteForProgrammingLanguages. </pre> <h3>B. Converting String to Upper Camel Case</h3> <p> <strong>UpperCamel.java</strong> </p> <pre> public class UpperCamel { // function to convert the string into upper camel case static String convertString( String s ) { // to keep track of spaces int ctr = 0 ; // variable to hold the length of the string int n = s.length( ) ; // converting the string expression to character array char ch[ ] = s.toCharArray( ) ; // // keep track of indices of ch[ ] array int c = 0 ; // traversing through each character of the array for ( int i = 0; i <n; 0 1 i++ ) { the first position of array i.e., letter must be converted to upper case. we checked this before second if statement as that is executed only when it encounters space and, there no a string. if( i="=" converting case using touppercase( in-built function ch[ ]="Character.toUpperCase(" ; need remove all spaces in between, check for empty ( ' incrementing counter by ctr++ immediately after + 1] continue loop } not encountered simply copy character else c++ new string will reduced have been removed thus returning with size return string.valueof( ch, 0, n - ctr driver code public static void main( args[ passing name method str="class test" system.out.println( convertstring( variable str1="employee" str2="this is the java tutorial" system.out.println(convertstring( < pre> <p> <strong>Output:</strong> </p> <pre> ClassTest Employee ThisIsTheJavaTutorial </pre> <hr></n;></pre></n;>

B. Conversione di una stringa in maiuscolo Camel superiore

UpperCamel.java

 public class UpperCamel { // function to convert the string into upper camel case static String convertString( String s ) { // to keep track of spaces int ctr = 0 ; // variable to hold the length of the string int n = s.length( ) ; // converting the string expression to character array char ch[ ] = s.toCharArray( ) ; // // keep track of indices of ch[ ] array int c = 0 ; // traversing through each character of the array for ( int i = 0; i <n; 0 1 i++ ) { the first position of array i.e., letter must be converted to upper case. we checked this before second if statement as that is executed only when it encounters space and, there no a string. if( i="=" converting case using touppercase( in-built function ch[ ]="Character.toUpperCase(" ; need remove all spaces in between, check for empty ( \' incrementing counter by ctr++ immediately after + 1] continue loop } not encountered simply copy character else c++ new string will reduced have been removed thus returning with size return string.valueof( ch, 0, n - ctr driver code public static void main( args[ passing name method str="class test" system.out.println( convertstring( variable str1="employee" str2="this is the java tutorial" system.out.println(convertstring( < pre> <p> <strong>Output:</strong> </p> <pre> ClassTest Employee ThisIsTheJavaTutorial </pre> <hr></n;>