Page 452 - CA_Blue( J )_Class10
P. 452
OUTPUT:
"TECHNOLOGY"
(ii) void joyString(String s) with one string argument that prints the position of the first space and the last space of the given
string s.
Example:
INPUT:
s = "Cloud computing means Internet-based computing"
OUTPUT:
First index: 5
Last index: 36
(iii) void joyString(String s1, String s2) with two string arguments that combines the two strings with a space between them
and prints the resultant string.
Example:
INPUT:
s1 = "COMMON WEALTH"
s2 = "GAMES"
OUTPUT:
COMMON WEALTH GAMES
(use library functions)
Ans. class Overload_function
{
void joyString(String s, char ch1, char ch2)
{
s = s.replace(ch1, ch2);
System.out.println(s);
}
void joyString(String s)
{
int f,l;
f = s.indexOf(' ');
l = s.lastIndexOf(' ');
System.out.println("First index: " + f);
System.out.println("Last index: " + l);
}
void joyString(String s1, String s2)
{
String s = s1 + " " + s2;
System.out.println(s);
}
}
24. Write a program to assign a full path and file name as given below. Using library functions, extract and output the file path, file
name and file extension separately as shown.
INPUT: C:\Users\admin\Pictures\flower.jpg
OUTPUT:
Path: C:\Users\admin\Pictures\
File name: flower
Extension: jpg [2014]
Ans. class show {
public static void main()
{
int slash,dot;
String path,fname,ext;
String str = "C:\\Users\\admin\\Pictures\\flower.jpg";
450450 Touchpad Computer Applications-X

