Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

compare 2 characters in java

public class JavaCharacterCompareExample1 {  
public static void main(String[] args) {  
char firstValue = 'A';  
char secondValue = 'B';  
// compare the first char to the second  
    int compareOneTwo = Character.compare(firstValue, secondValue);  
    if (compareOneTwo> 0) {  
    System.out.println("First value is greater than second value");  
    }  
    else {  
System.err.println("First value is less than second value.");  
    }  
   }  
}

// OUT:  First value is less than the second value.
Comment

how to compare two characters in java

If your input is a character and the characters you are checking against are mostly consecutive you could try this:

if ((symbol >= 'A' && symbol <= 'Z') || symbol == '?') {
    // ...
}
Comment

java compare char

don't forget to use single quotes('char') in stead of double quotes("String") like with String.
Comment

PREVIOUS NEXT
Code Example
Java :: how to set edittext color in android 
Java :: java hashtable 
Java :: java optional parameters 
Java :: math.round java 
Java :: The JAVA_HOME environment variable is not defined correctly, this environment variable is needed to run this program. 
Java :: java find largest number in list 
Java :: get last day of month java 
Java :: how to set current item for spinner android 
Java :: multiple return values in function java 
Java :: java enum from int 
Java :: mp3 player java 
Java :: convert python code to java 
Java :: xml button color not changing 
Java :: java, how to find the most repeated character 
Java :: java swing date picker 
Java :: 1.13. programacion orientada a objetos en java 
Java :: Java Scanner nextDouble() 
Java :: what is getService() in java 
Sql :: FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning. 
Sql :: sql server reset identity 
Sql :: loading local data is disabled mysql 
Sql :: check timezone of mysql database 
Sql :: grant revoke privileges to mysql username 
Sql :: stpop start psql server 
Sql :: postgresql calculate age from birthdate 
Sql :: reset mysql root password mac 
Sql :: find string in stored procedure sql server 
Sql :: postgres delete from where date is greater than specific date 
Sql :: mysql command line connect 
Sql :: mssql show database size 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =