logo

حالة الجمل في جاوة

تتبع Java صيغة الجمل لتسمية الفئات والواجهات والأساليب والمتغيرات. إذا تم دمج الاسم مع كلمتين، فإن الكلمة الثانية ستبدأ بأحرف كبيرة دائمًا، مثل maxMarks() و lastName و ClassTest، مع إزالة كافة المسافات البيضاء.

هناك طريقتان لاستخدام حالة الجمل:

  1. حالة الجمل السفلية حيث يكون الحرف الأول من الكلمة الأولى مكتوبًا بأحرف صغيرة. عادة ما يتم اتباع هذه الاتفاقية أثناء تسمية الطرق والمتغيرات. على سبيل المثال، الاسم الأول، والاسم الأخير، وactionEvent، وprintArray()، وما إلى ذلك.
  2. حالة الجمل العلوية تُعرف أيضًا باسم حالة العنوان، حيث يكون الحرف الأول من الكلمة الأولى مكتوبًا بأحرف كبيرة. عادةً ما يتم اتباع هذه الاتفاقية أثناء تسمية الفئات والواجهات. على سبيل المثال، الموظف، القابل للطباعة، وما إلى ذلك.

تحويل الخيط العادي إلى علبة الجمل

يمكن تحويل السلسلة إلى حالة الجمل السفلية أو العلوية فقط عن طريق إزالة المسافات من السلسلة.

مثال على حالة الجمل السفلية:

مدخل: JavaTpoint هو أفضل موقع تعليمي للغات البرمجة.

انتاج: javaTpointIsTheBestTutorialSiteForProgrammingLanguages.

مثال على حالة الجمل العلوي:

مدخل: هذا هو البرنامج التعليمي جافا

انتاج: ThisIsTheJavaTutorial

الخوارزمية:

  1. اجتياز مصفوفة الأحرف حرفًا تلو الآخر حتى تصل إلى النهاية.
  2. يتم تحويل الحرف الأول من السلسلة عند الفهرس = 0 إما إلى أحرف صغيرة (عند اتباع أحرف الجمل السفلية) أو إلى أحرف كبيرة (عند اتباع أحرف الجمل العلوية).
  3. يتم التحقق من وجود مسافات في المصفوفة، ويتم تحويل الحرف الذي يلي المسافة مباشرة إلى أحرف كبيرة.
  4. إذا تمت مصادفة حرف غير مسافة، فسيتم نسخه إلى المصفوفة الناتجة.

دعونا ننفذ الخوارزمية في برنامج جافا.

أ. تحويل السلسلة إلى حالة الجمل السفلية

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;>

ب. تحويل السلسلة إلى علبة الجمل العلوية

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;>