Page 448 - CA_Blue( J )_Class10
P. 448
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String st1,st2;
String nSt = "";
System.out.print("Enter a string1:");
st1 = sc.nextLine();
System.out.print("Enter a string2:");
st2 = sc.nextLine();
int l = st1.length();
for (int i = 0; i < l; i++)
{
nSt = nSt + st1.charAt(i) + st2.charAt(i);
}
System.out.println(nSt);
}
}
16. Design a class to overload a function check () as follows: [2017]
void check(String str, char ch) – to find and print the frequency of a character in a string.
Example:
INPUT: str = "success" ch = 's'
OUTPUT: Number of s present is = 3.
void check(String s1) – to display only vowels from s1, after converting it to lowercase.
Example:
INPUT:
s1 = "computer"
OUTPUT:
o u e
Ans. class Overload_string
{
public static void check(String str, char ch)
{
int count = 0,i;
for(i = 0; i < str.length(); i++)
{
if(ch == str.charAt(i))
count++;
}
System.out.println("Number of "+ ch + " present is= " + count);
}
public static void check(String s1)
{
char ch;int i;
s1 = s1.toLowerCase();
for(i = 0; i < s1.length(); i++)
{
ch = s1.charAt(i);
if(ch=='a' || ch=='e' || ch=='i' || ch=='0' || ch=='u')
446446 Touchpad Computer Applications-X

