java - char can not be dereferenced charAt().compareTo() -


public static void main(string[] args) {     scanner in= new scanner(system.in);     string time= in.nextline();     string arr[]=time.split(":");    // system.out.println(arr[0]);     string pm="p";     if(!(arr[2].charat(2)).compareto(pm)) //i error here          {         arr[0]+=12;         system.out.print(arr[0]+":"+arr[1]+":"+arr[2]);     }     if((arr[2].charat(2)).compareto(pm)!=0) //i error here         {         system.out.print(arr[0]+":"+arr[1]+":"+arr[2]);     } } 

please me remove errors ! have check if time input has or pm.

char doesn't have compareto method - or methods, matter, since primitive.

you can compare primitives using relational operators <, > , ==.

since pm single-character string, can change type char:

char pm = 'p'; 

and use != compare, e.g.

if (arr[2].charat(2) != pm) {    // .. whatever. 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -