Page 191 - CA_Blue( J )_Class10
P. 191
{
Scanner sc= new Scanner(System.in);
int ch,i,j;
System.out.println("1. Letters and Unicode");
System.out.println("2. Traingle");
System.out.print("Enter your choice: ");
ch = sc.nextInt();
switch(ch)
{
case 1:
System.out.println("Letters\tUnicode");
for(i = 65; i <= 90; i++)
{
System.out.println((char)i + "\t" + i);
}
break;
case 2:
for(i = 1; i <= 5; i++)
{
for(j = 1; j <= i; j++)
{
System.out.print(j + " ");
}
System.out.println();
}
break;
default: System.out.println("Wrong choice");
}
}
}
18. Write a program to input a sentence and convert it into uppercase and count and display the total number of words starting
with the letter ‘A’.
Example:
Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING.
Sample Output: Total number of words starting with the letter ‘A’ = 4. [2019]
Ans. import java.util.*;
class question8
{
public static void main()
{
Scanner sc= new Scanner(System.in);
String s,word="";
int c=0,i;
char ch1,ch2;
System.out.print("Enter the sentence: ");
s = sc.nextLine();
s = " " + s;
for(i = 0; i < s.length()-1; i++)
{
ch1 = s.charAt(i);
ch2 = s.charAt(i+1);
if(ch1==' ' && ch2=='A')
{
c++;
}
}
System.out.println("Total number of words starting with letter 'A' = " + c);
}
}
189
Iterative constructs in Java 189

