String methods!
class Pro1{
public static void main(String args[]){
String adrs = "32/A, Temple Road, Colombo";
//length of the address!
System.out.println(adrs.length());
//find 15th character
System.out.println(adrs.charAt(11));
//find letter e
System.out.println(adrs.indexOf('e'));
//find last o
System.out.println(adrs.lastIndexOf('o'));
//print all after 2nd coma
int coma2 = adrs.lastIndexOf(',');
System.out.println(adrs.substring(coma2+1));
//print all BTW 2 comas
int coma1 = adrs.indexOf(',');
System.out.println(adrs.substring(coma1+1, coma2));
//whole convert to upper case
System.out.println(adrs.toUpperCase());
//whole convert to lower case
System.out.println(adrs.toLowerCase());
//print whole address
System.out.println(adrs.toCharArray());
//add another colombo part to adress
String city = adrs.substring(coma2+1);
System.out.println(adrs.concat(city));
}
}
public static void main(String args[]){
String adrs = "32/A, Temple Road, Colombo";
//length of the address!
System.out.println(adrs.length());
//find 15th character
System.out.println(adrs.charAt(11));
//find letter e
System.out.println(adrs.indexOf('e'));
//find last o
System.out.println(adrs.lastIndexOf('o'));
//print all after 2nd coma
int coma2 = adrs.lastIndexOf(',');
System.out.println(adrs.substring(coma2+1));
//print all BTW 2 comas
int coma1 = adrs.indexOf(',');
System.out.println(adrs.substring(coma1+1, coma2));
//whole convert to upper case
System.out.println(adrs.toUpperCase());
//whole convert to lower case
System.out.println(adrs.toLowerCase());
//print whole address
System.out.println(adrs.toCharArray());
//add another colombo part to adress
String city = adrs.substring(coma2+1);
System.out.println(adrs.concat(city));
}
}
Post a Comment