Page 453 - CA_Blue( J )_Class10
P. 453
slash = str.lastIndexOf('\\');
dot = str.lastIndexOf('.');
path = str.substring(0, slash + 1);
fname = str.substring(slash + 1, dot);
ext = str.substring(dot + 1);
System.out.println("Path: " + path);
System.out.println("File name: " + fname);
System.out.println("Extension: " + ext);
}
}
25. Write a program that encodes a word into Piglatin. To translate word into Piglatin word, convert the word into uppercase and
then place the first vowel of the original word as the start of the new word along with the remaining alphabets. The alphabets
present before the vowel being shifted towards the end followed by "AY".
Sample Input 1: London
Output: ONDONLAY
Sample Input 2: Olympics
Output: OLYMPICSAY [2013]
Ans. Refer question 8 of solved program
26. Write a program to accept a string. Convert the string to uppercase. Count and output the number of double letter sequences
that exist in the string.
Sample Input: "SHE WAS FEEDING THE LITTLE RABBIT WITH AN APPLE"
Sample Output: 4 [2012]
Ans. import java.util.*;
class consequtive {
public static void main()
{
Scanner sc= new Scanner(System.in);
String str;
int len,c=0,i;
char ch1,ch2;
System.out.print("Enter a sentence : ");
str = sc.nextLine();
len = str.length();
for(i = 0; i < len - 1; i++)
{
ch1 = str.charAt(i);
ch2 = str.charAt(i + 1);
if(Character.isLetter(ch1) && Character.isLetter(ch2) &&(ch1 == ch2))
{ c++;
}
}
System.out.println(c);
}
}
451
String Handling 451

