Lexicographic Increasing Order

Lexicographic increasing order refers to arranging elements or objects in ascending order based on their lexicographic order. In lexicographic order, elements are compared character by character, and the order is determined by the alphabetical or numerical value of each character. For example, consider a list of strings: ["apple", "banana", "cherry", "apricot"]. When arranged in lexicographic increasing order, the list would be ["apricot", "apple", "banana", "cherry"]. The comparison starts with the first character of each string, and if the characters are equal, the comparison moves to the next character. In this case, "apricot" comes before "apple" because 'p' comes before 'p' and 'r' comes before 'p'. Similarly, "apple" comes before "banana" because 'a' comes before 'b'. The concept of lexicographic increasing order

Java program to take two string as command line arguments and check that they are equal or not.

java program

 
/*

Do not use '==' operator for comparing strings in java. 
Because '==' checks if both objects point to the same memory address or location 
and .equals() compares values in the objects.

This program is made using library functions and without using library functions.

Here in this program I am using string library functions .equals() and .equalsIgnoreCase()
which gives output as boolean values true or false.

*/

import java.util.*;

public class str_cmp_cmd_line
{
    public static void main(String[] args)
    {

     System.out.println("First Input String ="+args[0]);
     //Commmand line arguments always starts from 0 i.e. args[0]
     System.out.println("Second Input String ="+args[1]);
    System.out.println("By using string library function of equals()");
    System.out.println("Input string1= "+args[0]+" & string2= "+args[1]+" are equal :"+args[0].equals(args[1]));
    // Here equals() checks each character with its order and also compares lowercase-uppercase letter
    System.out.println("By using string library function of equalsIgnoreCase()");
    //which ignores lower or uppercase of letters input and gives boolean value as true or false
    System.out.println("Input string1= "+args[0]+" & string2= "+args[1]+" are equal :             "+args[0].equalsIgnoreCase(args[1]));
    //Without using library functions
    int i,flag=1,len1,len2;
    len1=args[0].length();
    len2=args[1].length();
    char str1[] = args[0].toCharArray();
    char str2[] = args[1].toCharArray();
 
    if(len1==len2)
    
for(i=0;i<len1;i++)
{
     if(str1[i]!=str2[i])
    {
flag=0;
break;
    }
}
    }
    else
    {
flag=0; 
    
     if(flag==1)
    {
        System.out.println("The two string are EQUAL!!!");
System.out.println(args[0]+" = "+args[1]);
    }
    else
    {
        System.out.println("The two string are NOT EQUAL!!!");
        System.out.println(args[0]+" != "+args[1]);
    }
    }
}
/*

E:\java_prog>javac str_cmp_cmd_line.java

E:\java_prog>java str_cmp_cmd_line asd Asd

First Input String =asd
Second Input String =Asd
By using string library function of equals()
Input string1= asd & string2= Asd are equal : false
By using string library function of equalsIgnoreCase()
Input string1= asd & string2= Asd are equal : true
The two string are NOT EQUAL!!!
asd != Asd

E:\java_prog>java str_cmp_cmd_line asd asd

First Input String =asd
Second Input String =asd
By using string library function of equals()
Input string1= asd & string2= asd are equal : true
By using string library function of equalsIgnoreCase()
Input string1= asd & string2= asd are equal : true
The two string are EQUAL!!!
asd = asd

*/
// Java Programs | string Compare | String equal |

Comments

Popular posts from this blog

Implement the following class hierarchy: Student: id, name, StudentExam (derived from Student): with n subjects (n can be variable) StudentResult (derived from StudentExam): with percentage, grade. Define a parameterized constructor for each class and appropriate functions to accept and display details. Create n objects of the StudentResult class and display the marklist using suitable manipulators.| CPP programs |

Lexicographic Increasing Order

Different Types of Computer Programming Languages