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
Post a Comment